/*
 * 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 = 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 = 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);
}
