/* * pseudo_server.c, pseudo's server-side logic and message handling * * Copyright (c) 2008-2010 Wind River Systems, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the Lesser GNU General Public License version 2.1 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the Lesser GNU General Public License for more details. * * You should have received a copy of the Lesser GNU General Public License * version 2.1 along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <errno.h> #include <unistd.h> #include <fcntl.h> #include <sys/select.h> #include <sys/time.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #include <sys/stat.h> #include <sys/wait.h> #include <signal.h> #include "pseudo.h" #include "pseudo_ipc.h" #include "pseudo_server.h" #include "pseudo_client.h" #include "pseudo_db.h" static int listen_fd = -1; typedef struct { int fd; pid_t pid; char *tag; char *program; } pseudo_client_t; pseudo_client_t *clients; /* active_clients: Number of clients we actually have right now. * highest_client: Highest index into clients table of an active client. * max_clients: Size of table. */ static int active_clients = 0, highest_client = 0, max_clients = 0; #define LOOP_DELAY 2 int pseudo_server_timeout = 30; static int die_peacefully = 0; static int die_forcefully = 0; /* when the client is linked with pseudo_wrappers, these are defined there. * when it is linked with pseudo_server, though, we have to provide different * versions (pseudo_wrappers must not be linked with the server, or Bad Things * happen). */ void pseudo_magic(void) { } void pseudo_antimagic(void) { } void quit_now(int signal) { pseudo_diag("Received signal %d, quitting.\n", signal); die_forcefully = 1; } static int messages = 0; static struct timeval message_time = { .tv_sec = 0 }; static void pseudo_server_loop(void); int pseudo_server_start(int daemonize) { struct sockaddr_un sun = { AF_UNIX, PSEUDO_SOCKET }; char *pseudo_path; int rc, newfd; FILE *fp; listen_fd = socket(PF_UNIX, SOCK_STREAM, 0); if (listen_fd < 0) { pseudo_diag("couldn't create listening socket: %s\n", strerror(errno)); return 1; } if (listen_fd <= 2) { newfd = fcntl(listen_fd, F_DUPFD, 3); if (newfd < 0) { pseudo_diag("couldn't dup listening socket: %s\n", strerror(errno)); close(listen_fd); return 1; } else { close(listen_fd); listen_fd = newfd; } } /* cd to the data directory */ pseudo_path = pseudo_localstatedir_path(NULL); if (!pseudo_path || chdir(pseudo_path) == -1) { pseudo_diag("can't get to '%s': %s\n", pseudo_path, strerror(errno)); return 1; } free(pseudo_path); /* remove existing socket -- if it exists */ unlink(sun.sun_path); if (bind(listen_fd, (struct sockaddr *) &sun, sizeof(sun<#include <linux/kernel.h> extern const char __initconst *const blacklist_hashes[];
#include <linux/kernel.h> extern const char __initconst *const blacklist_hashes[];