/*
 * tiny fuser implementation 
 * 
 * Copyright 2004 Tony J. White
 *
 * May be distributed under the conditions of the
 * GNU Library General Public License
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <dirent.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include "busybox.h"

#define FUSER_PROC_DIR "/proc"
#define FUSER_MAX_LINE 255

#define FUSER_OPT_MOUNT  1
#define FUSER_OPT_KILL   2
#define FUSER_OPT_SILENT 4 
#define FUSER_OPT_IP6    8 
#define FUSER_OPT_IP4    16 

typedef struct inode_list {
	ino_t inode;
	dev_t dev;
	struct inode_list *next;
} inode_list;

typedef struct pid_list {
	pid_t pid;
	struct pid_list *next;
} pid_list;

static int fuser_option(char *option) 
{
	int opt = 0;

	if(!(strlen(option))) return 0;
	if(option[0] != '-') return 0;
	*++option;
	while(*option != '\0') {
		if(*option == 'm') opt |= FUSER_OPT_MOUNT;
		else if(*option == 'k') opt |= FUSER_OPT_KILL;
		else if(*option == 's') opt |= FUSER_OPT_SILENT;
		else if(*option == '6') opt |= FUSER_OPT_IP6;
		else if(*option == '4') opt |= FUSER_OPT_IP4;
		else {
			bb_error_msg_and_die(
				"Unsupported option '%c'", *option); 
		}
		*++option;
	}
	return opt;
}

static int fuser_file_to_dev_inode(const char *filename,
	 dev_t *dev, ino_t *inode)
{
	struct stat f_stat;
	if((stat(filename, &f_stat)) < 0) return 0;
	*inode = f_stat.st_ino;
	*dev = f_stat.st_dev;
        return 1;
}

static int fuser_find_socket_dev(dev_t *dev) {
	int fd = socket(PF_INET, SOCK_DGRAM,0);
	struct stat buf;
	
	if (fd >= 0 && (fstat(fd, &buf)) == 0) {
		*dev =  buf.st_dev;
		close(fd);
		return 1;
	}
	return 0;
}

static int fuser_parse_net_arg(const char *filename, 
	const char **proto, int *port) 
{
	char path[sizeof(FUSER_PROC_DIR)+12], tproto[5];

	if((sscanf(filename, "%d/%4s", port, tproto)) != 2) return 0;
	sprintf(path, "%s/net/%s", FUSER_PROC_DIR, tproto);
	if((access(path, R_OK)) != 0) return 0;
	*proto = bb_xstrdup(tproto);
	return 1;	
}

static int fuser_add_pid(pid_list *plist, pid_t pid)
{
        pid_list *curr = NULL, *last = NULL;
        
        if(plist->pid == 0) plist->pid = pid;
        curr = plist;
        while(curr != NULL) {
                if(curr->pid == pid) return 1;
                last = curr;
                curr = curr->next;
        }
        curr = xmalloc(sizeof(pid_list));
        last->next = curr;
        curr->pid = pid;
	curr->next = NULL;
        return 1;
}

static int fuser_add_inode(inode_list *ilist, dev_t dev, ino_t inode)
{
        inode_list *curr = NULL, *last = NULL;
                                                                                
        if(!ilist->inode && !ilist->dev) {
		ilist->dev = dev;
		ilist->inode = inode;
	}
        curr = ilist;
        while(curr != NULL) {
                if(curr->inode == inode && curr->dev == dev) return 1;
                last = curr;
                curr = curr->next;
        }
        curr = xmalloc(sizeof(inode_list));
        last->next = curr;
        curr->dev = dev;
        curr->inode = inode;
	curr->next = NULL;
        return 1;
}

static int fuser_scan_proc_net(int opts, const char *proto, 
	int port, inode_list *ilist) 
{
	char path[sizeof(FUSER_PROC_DIR)+12], line[FUSER_MAX_LINE+1];
	char addr[128];
	ino_t tmp_inode;
	dev_t tmp_dev;
	uint64_t  uint64_inode;
	int tmp_port;
	FILE *f;

	if(!fuser_find_socket_dev(&tmp_dev)) tmp_dev = 0;
	sprintf(path, "%s/net/%s", FUSER_PROC_DIR, proto);

	if (!(f = fopen(path, "r"))) return 0;
	while(fgets(line, FUSER_MAX_LINE, f)) {
		if(sscanf(line,
			"%*d: %64[0-9A-Fa-f]:%x %*x:%*x %*x %*x:%*x "
			"%*x:%*x %*x %*d %*d %llu",
			addr, &tmp_port, &uint64_inode) == 3) {
			if((strlen(addr) == 8) && 
				(opts & FUSER_OPT_IP6)) continue;
			else if((strlen(addr) > 8) &&
				(opts & FUSER_OPT_IP4)) continue; 
			if(tmp_port == port) {
				tmp_inode = uint64_inode;
				fuser_add_inode(ilist, tmp_dev, tmp_inode);
			}
		}

	}
	fclose(f);
	return 1;
}

static int fuser_search_dev_inode(int opts, inode_list *ilist, 
	dev_t dev, ino_t inode) 
{
        inode_list *curr;
        curr = ilist;

        while(curr) {
		if((opts & FUSER_OPT_MOUNT) &&  curr->dev == dev)
			return 1;
		if(curr->inode == inode && curr->dev == dev)
			return 1;
                curr = curr->next;
        }
        return 0;
}

static int fuser_scan_pid_maps(int opts, const char *fname, pid_t pid,
	inode_list *ilist, pid_list *plist) 
{
	FILE *file;
	char line[FUSER_MAX_LINE + 1];
	int major, minor;
	ino_t inode;
	uint64_t uint64_inode;
	dev_t dev;

	if (!(file = fopen(fname, "r"))) return 0;
	while (fgets(line, FUSER_MAX_LINE, file)) {
		if(sscanf(line, "%*s %*s %*s %x:%x %llu", 
			&major, &minor, &uint64_inode) != 3) continue;
		inode = uint64_inode;
		if(major == 0 && minor == 0 && inode == 0) continue;
		dev = makedev(major, minor);		
		if(fuser_search_dev_inode(opts, ilist, dev, inode)) {
			fuser_add_pid(plist, pid);
		}
		
	}
	fclose(file);
	return 1;
}

static int fuser_scan_link(int opts, const char *lname, pid_t pid, 
	inode_list *ilist, pid_list *plist) 
{
	ino_t inode;
	dev_t dev;	

	if(!fuser_file_to_dev_inode(lname, &dev, &inode)) return 0;
	if(fuser_search_dev_inode(opts, ilist, dev, inode)) 
		fuser_add_pid(plist, pid);
	return 1;
}

static int fuser_scan_dir_links(int opts, const char *dname, pid_t pid,
	inode_list *ilist, pid_list *plist)
{
	DIR *d;
	struct dirent *de;
	char *lname;

	if((d = opendir(dname))) {
		while((de = readdir(d)) != NULL) {
			lname = concat_subpath_file(dname, de->d_name);
			if(lname == NULL)
				continue;
			fuser_scan_link(opts, lname, pid, ilist, plist);
			free(lname);
		}
		closedir(d);
	}
	else return 0;
	return 1;

} 

static int fuser_scan_proc_pids(int opts, inode_list *ilist, pid_list *plist) 
{
	DIR *d;
	struct dirent *de;
	pid_t pid;
	char *dname;

	if(!(d = opendir(FUSER_PROC_DIR))) return 0;
	while((de = readdir(d)) != NULL) {
		pid = (pid_t)atoi(de->d_name);
		if(!pid) continue;
		dname = concat_subpath_file(FUSER_PROC_DIR, de->d_name);
		if(chdir(dname) < 0) {
			free(dname);
			continue; 
		}
		free(dname);
		fuser_scan_link(opts, "cwd", pid, ilist, plist);
		fuser_scan_link(opts, "exe", pid, ilist, plist);
		fuser_scan_link(opts, "root", pid, ilist, plist);
		fuser_scan_dir_links(opts, "fd", pid, ilist, plist);
		fuser_scan_dir_links(opts, "lib", pid, ilist, plist);
		fuser_scan_dir_links(opts, "mmap", pid, ilist, plist);
		fuser_scan_pid_maps(opts, "maps", pid, ilist, plist);
		chdir("..");
	} 
	closedir(d);	
	return 1;
}

static int fuser_print_pid_list(pid_list *plist) {
	pid_list *curr;
	curr = plist;

	if(plist == NULL) return 0;
	while(curr != NULL) {
		if(curr->pid > 0) printf("%d ", curr->pid);
		curr = curr->next;
	}
	printf("\n");
	return 1;
}

static int fuser_kill_pid_list(pid_list *plist, int sig) {
        pid_list *curr;
        curr = plist;
	pid_t mypid = getpid();
	int success = 1;

	if(plist == NULL) return 0;
        while(curr != NULL) {
		if(curr->pid > 0 && curr->pid != mypid) {
			if (kill(curr->pid, sig) != 0) { 
                                bb_perror_msg(
					"Could not kill pid '%d'", curr->pid);
				success = 0;		
			}
		}
                curr = curr->next;
        }
        return success;
}

extern int fuser_main(int argc, char **argv) {
	int port, i, optn;
	int* fni; /* file name indexes of argv */
	int fnic = 0;  /* file name index count */
	const char *proto;
	static int opt = 0; /* FUSER_OPT_ */
	dev_t dev;
	ino_t inode;
	pid_list *pids;
	inode_list *inodes;
	int killsig = SIGTERM;
	int success = 1;

	fni = xmalloc(sizeof(int));
	for(i=1;i<argc;i++) {
		optn = fuser_option(argv[i]);
		if(optn) opt |= optn; 
		else if(argv[i][0] == '-') {
			if(!(u_signal_names(argv[i]+1, &killsig, 0)))
				killsig = SIGTERM;
		}
		else {
			fni = xrealloc(fni, sizeof(int) * (fnic+2));
			fni[fnic++] = i;
		}
	}
	if(!fnic) return 1;

	pids = xmalloc(sizeof(pid_list));
	inodes = xmalloc(sizeof(inode_list));
	for(i=0;i<fnic;i++) {
		if(fuser_parse_net_arg(argv[fni[i]], &proto, &port)) {
			fuser_scan_proc_net(opt, proto, port, inodes);
		}
		else {
			if(!fuser_file_to_dev_inode(
				argv[fni[i]], &dev, &inode)) {
				free(pids);
				free(inodes);
				bb_perror_msg_and_die(
					"Could not open '%s'", argv[fni[i]]);
			}
			fuser_add_inode(inodes, dev, inode);
		}
	}
	success = fuser_scan_proc_pids(opt, inodes, pids);
	/* if the first pid in the list is 0, none have been found */
	if(pids->pid == 0) success = 0;
	if(success) {
		if(opt & FUSER_OPT_KILL) {
			success = fuser_kill_pid_list(pids, killsig);
		}
		else if(!(opt & FUSER_OPT_SILENT)) {
			success = fuser_print_pid_list(pids);
		}
	}
	free(pids);
	free(inodes);
	/* return 0 on (success == 1) 1 otherwise */
	return (success != 1);
} 
