static int print_matches(struct names *names_head, const opt_type opts, const int sig_number);
static void kill_matched_proc(struct procs *pptr, const opt_type opts, const int sig_number);
-static dev_t get_netdev(void);
int parse_mount(struct names *this_name, struct device_list **dev_list);
static void add_device(struct device_list **dev_list, struct names *this_name, dev_t device);
void scan_mount_devices(const opt_type opts, struct mountdev_list **mount_devices);
-void scan_unixsockets(struct unixsocket_list **unixsocket_head);
+void fill_unix_cache(struct unixsocket_list **unixsocket_head);
+static dev_t find_net_dev(void);
#ifdef DEBUG
static void debug_match_lists(struct names *names_head, struct inode_list *ino_head, struct device_list *dev_head);
#endif
int parse_unixsockets(struct names *this_name, struct inode_list **ino_list, struct unixsocket_list *sun_head)
{
struct unixsocket_list *sun_tmp;
+ struct stat st;
+ dev_t net_dev;
+
+ if (stat(this_name->filename, &st) != 0) {
+ fprintf(stderr,_("Cannot stat %s: %s\n"), this_name->filename,
+ strerror(errno));
+ return -1;
+ }
+ net_dev = find_net_dev();
for (sun_tmp = sun_head; sun_tmp != NULL ; sun_tmp = sun_tmp->next)
{
- if (strcmp(this_name->filename, sun_tmp->sun_name) == 0) {
- add_inode(ino_list, this_name, sun_tmp->dev, sun_tmp->inode);
+ if (sun_tmp->dev == st.st_dev && sun_tmp->inode == st.st_ino) {
+ add_inode(ino_list, this_name, net_dev, sun_tmp->net_inode);
+ return 0;
}
}
return 0;
/*printf("Found %ld with %s:%ld\n", loc_port, rmt_addr6str, rmt_port);*/
for(conn_tmp = conn_list ; conn_tmp != NULL ; conn_tmp = conn_tmp->next) {
inet_ntop(AF_INET6, &conn_tmp->rmt_address, rmt_addr6str, INET6_ADDRSTRLEN);
- /* printf("Comparing with *.%lu %s:%lu ...",
+ /*printf("Comparing with *.%lu %s:%lu ...\n\n",
conn_tmp->lcl_port,
rmt_addr6str,
conn_tmp->rmt_port);*/
opts = 0;
sig_number = SIGKILL;
- netdev = get_netdev();
+ netdev = find_net_dev();
scan_mount_devices(opts, &mount_devices);
- scan_unixsockets(&unixsockets);
+ fill_unix_cache(&unixsockets);
/* getopt doesnt like things like -SIGBLAH */
for(optc = 1; optc < argc; optc++) {
char first = 1;
int len = 0;
struct passwd *pwent = NULL;
- int have_match = 0;
+ int have_match = 1;
for (nptr = names_head; nptr != NULL ; nptr = nptr->next) {
if (! (opts & OPT_SILENT)) { /* We're not silent */
kill_matched_proc(nptr->matched_procs, opts, sig_number);
} /* next name */
- return !have_match;
+ return (have_match==1?0:1);
}
}
/*
- * scan_unixsockets : Create a list of Unix sockets
+ * fill_unix_cache : Create a list of Unix sockets
* This list is used later for matching purposes
*/
-void scan_unixsockets(struct unixsocket_list **unixsocket_head)
+void fill_unix_cache(struct unixsocket_list **unixsocket_head)
{
FILE *fp;
char line[BUFSIZ];
if ( (newsocket = malloc(sizeof(struct unixsocket_list))) == NULL)
continue;
newsocket->sun_name = strdup(scanned_path);
- newsocket->inode = scanned_inode; /* st.st_ino;*/
- newsocket->dev = 0; /* st.st_dev;*/
+ newsocket->inode = st.st_ino;
+ newsocket->dev = st.st_dev;
+ newsocket->net_inode = scanned_inode;
newsocket->next = *unixsocket_head;
*unixsocket_head = newsocket;
} /* while */
}
}
-static dev_t get_netdev(void)
-{
- int skt;
- struct stat st;
-
- if ( (skt = socket(PF_INET,SOCK_DGRAM,0)) < 0)
- return -1;
- if ( fstat(skt, &st) != 0)
- return -1;
- return st.st_dev;
-}
-
#ifdef DEBUG
/* often not used, doesnt need translation */
static void debug_match_lists(struct names *names_head, struct inode_list *ino_head, struct device_list *dev_head)
}
}
+
+static dev_t find_net_dev(void)
+{
+ int skt;
+ struct stat st;
+
+ if ( (skt = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+ fprintf(stderr,_("Cannot open a network socket.\n"));
+ return -1;
+ }
+ if ( fstat(skt, &st) != 0) {
+ fprintf(stderr,_("Cannot find socket's device number.\n"));
+ close(skt);
+ return -1;
+ }
+ close(skt);
+ return st.st_dev;
+}
+
+