Attached is a patch that move body of lonely functions to the place of their 
calls.

function                                             old     new   delta
fuser_main                                           911     877     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-34)             Total: -34 bytes

Also my gcc (4.4.4) writes the type punning warnings around
#define G (* (struct globals *) & bb_common_bufsiz1).
Is it dangerous?

gcc output:
  CC      procps/fuser.o
procps/fuser.c: In function 'add_pid':
procps/fuser.c:45: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
procps/fuser.c: In function 'add_inode':
procps/fuser.c:59: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
procps/fuser.c: In function 'search_dev_inode':
procps/fuser.c:118: warning: dereferencing type-punned pointer will break 
strict-aliasing rules
procps/fuser.c: In function 'fuser_main':
procps/fuser.c:287: warning: dereferencing type-punned pointer will break 
strict-aliasing rules

> 
> Applied with more modifications on top.
> Please review:
> 
> http://git.busybox.net/busybox/commit/?id=fef9ee70727452954d2c5d28cc65e8b0fffcd6f1
> http://git.busybox.net/busybox/patch/?id=fef9ee70727452954d2c5d28cc65e8b0fffcd6f1
> 
> Thanks!
> -- 
> vda
> 
> 
> 
diff --git a/procps/fuser.c b/procps/fuser.c
index 7465d45..e56880c 100644
--- a/procps/fuser.c
+++ b/procps/fuser.c
@@ -40,31 +40,6 @@ struct globals {
 #define INIT_G() do { } while (0)
 
 
-static dev_t find_socket_dev(void)
-{
-	int fd = socket(AF_INET, SOCK_DGRAM, 0);
-	if (fd >= 0) {
-		struct stat buf;
-		int r = fstat(fd, &buf);
-		close(fd);
-		if (r == 0)
-			return buf.st_dev;
-	}
-	return 0;
-}
-
-static char *parse_net_arg(const char *arg, unsigned *port)
-{
-	char path[20], tproto[5];
-
-	if (sscanf(arg, "%u/%4s", port, tproto) != 2)
-		return NULL;
-	sprintf(path, "/proc/net/%s", tproto);
-	if (access(path, R_OK) != 0)
-		return NULL;
-	return xstrdup(path);
-}
-
 static void add_pid(const pid_t pid)
 {
 	pid_list **curr = &G.pid_list_head;
@@ -104,8 +79,15 @@ static void scan_proc_net(const char *path, unsigned port)
 	unsigned tmp_port;
 	FILE *f;
 	struct stat st;
+	int fd;
 
-	st.st_dev = find_socket_dev();
+	// find socket dev
+	fd = socket(AF_INET, SOCK_DGRAM, 0);
+	if (fd >= 0) {
+		if (fstat(fd, &st) < 0)
+			st.st_dev = 0;
+		close(fd);
+	}
 
 	f = fopen_for_read(path);
 	if (!f)
@@ -284,11 +266,15 @@ Find processes which use FILEs or PORTs
 
 	pp = argv;
 	while (*pp) {
-		char *path = parse_net_arg(*pp, &port);
-		if (path) { /* PORT/PROTO */
+		// parse net arg
+		char path[20], tproto[5];
+		if (sscanf(*pp, "%u/%4s", &port, tproto) != 2)
+			goto file;
+		sprintf(path, "/proc/net/%s", tproto);
+		if (access(path, R_OK) != 0) { /* PORT/PROTO */
 			scan_proc_net(path, port);
-			free(path);
 		} else { /* FILE */
+	  file:
 			xstat(*pp, &st);
 			add_inode(&st);
 		}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to