aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Koenig <jk@jk.fr.eu.org>2010-03-26 19:08:53 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-26 19:08:53 +0100
commitfbedacfc8caa1ec8f14e664a881cb0a93c8f8712 (patch)
tree6c08780bbaad6320149930bdbcfbee5a2eed9f5d
parent35fdb1bc9cb82fa5630c2d40ae49110ecd7c88ea (diff)
downloadbusybox-w32-fbedacfc8caa1ec8f14e664a881cb0a93c8f8712.tar.gz
busybox-w32-fbedacfc8caa1ec8f14e664a881cb0a93c8f8712.tar.bz2
busybox-w32-fbedacfc8caa1ec8f14e664a881cb0a93c8f8712.zip
Hurd compat fixes. Mostly dealing with absent PATH_MAX
Signed-off-by: Jérémie Koenig <jk@jk.fr.eu.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/realpath.c16
-rw-r--r--debianutils/start_stop_daemon.c33
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/safe_gethostname.c6
-rw-r--r--libbb/xconnect.c10
-rw-r--r--libbb/xreadlink.c6
-rw-r--r--scripts/basic/docproc.c22
-rw-r--r--scripts/basic/fixdep.c4
-rw-r--r--scripts/kconfig/confdata.c3
-rw-r--r--scripts/kconfig/mconf.c2
-rw-r--r--scripts/kconfig/zconf.l3
-rw-r--r--scripts/kconfig/zconf.y6
-rw-r--r--util-linux/umount.c33
13 files changed, 85 insertions, 61 deletions
diff --git a/coreutils/realpath.c b/coreutils/realpath.c
index 28906ba55..90a71ed7d 100644
--- a/coreutils/realpath.c
+++ b/coreutils/realpath.c
@@ -17,30 +17,20 @@ int realpath_main(int argc UNUSED_PARAM, char **argv)
17{ 17{
18 int retval = EXIT_SUCCESS; 18 int retval = EXIT_SUCCESS;
19 19
20#if PATH_MAX > (BUFSIZ+1)
21 RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX);
22# define resolved_path_MUST_FREE 1
23#else
24#define resolved_path bb_common_bufsiz1
25# define resolved_path_MUST_FREE 0
26#endif
27
28 if (!*++argv) { 20 if (!*++argv) {
29 bb_show_usage(); 21 bb_show_usage();
30 } 22 }
31 23
32 do { 24 do {
33 if (realpath(*argv, resolved_path) != NULL) { 25 char *resolved_path = xmalloc_realpath(*argv);
26 if (resolved_path != NULL) {
34 puts(resolved_path); 27 puts(resolved_path);
28 free(resolved_path);
35 } else { 29 } else {
36 retval = EXIT_FAILURE; 30 retval = EXIT_FAILURE;
37 bb_simple_perror_msg(*argv); 31 bb_simple_perror_msg(*argv);
38 } 32 }
39 } while (*++argv); 33 } while (*++argv);
40 34
41#if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE
42 RELEASE_CONFIG_BUFFER(resolved_path);
43#endif
44
45 fflush_stdout_and_exit(retval); 35 fflush_stdout_and_exit(retval);
46} 36}
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index dfc72f01a..0a0802575 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -89,16 +89,17 @@ enum {
89#define TEST (option_mask32 & OPT_TEST) 89#define TEST (option_mask32 & OPT_TEST)
90 90
91struct globals { 91struct globals {
92 struct pid_list *found; 92 struct pid_list *found_procs;
93 char *userspec; 93 char *userspec;
94 char *cmdname; 94 char *cmdname;
95 char *execname; 95 char *execname;
96 char *pidfile; 96 char *pidfile;
97 char *execname_cmpbuf;
98 unsigned execname_sizeof;
97 int user_id; 99 int user_id;
98 smallint signal_nr; 100 smallint signal_nr;
99} FIX_ALIASING; 101} FIX_ALIASING;
100#define G (*(struct globals*)&bb_common_bufsiz1) 102#define G (*(struct globals*)&bb_common_bufsiz1)
101#define found (G.found )
102#define userspec (G.userspec ) 103#define userspec (G.userspec )
103#define cmdname (G.cmdname ) 104#define cmdname (G.cmdname )
104#define execname (G.execname ) 105#define execname (G.execname )
@@ -118,7 +119,7 @@ struct globals {
118static int pid_is_exec(pid_t pid) 119static int pid_is_exec(pid_t pid)
119{ 120{
120 struct stat st; 121 struct stat st;
121 char buf[sizeof("/proc//exe") + sizeof(int)*3]; 122 char buf[sizeof("/proc/%u/exe") + sizeof(int)*3];
122 123
123 sprintf(buf, "/proc/%u/exe", (unsigned)pid); 124 sprintf(buf, "/proc/%u/exe", (unsigned)pid);
124 if (stat(buf, &st) < 0) 125 if (stat(buf, &st) < 0)
@@ -133,13 +134,13 @@ static int pid_is_exec(pid_t pid)
133static int pid_is_exec(pid_t pid) 134static int pid_is_exec(pid_t pid)
134{ 135{
135 ssize_t bytes; 136 ssize_t bytes;
136 char buf[PATH_MAX]; 137 char buf[sizeof("/proc/%u/cmdline") + sizeof(int)*3];
137 138
138 sprintf(buf, "/proc/%u/cmdline", (unsigned)pid); 139 sprintf(buf, "/proc/%u/cmdline", (unsigned)pid);
139 bytes = open_read_close(buf, buf, sizeof(buf) - 1); 140 bytes = open_read_close(buf, G.execname_cmpbuf, G.execname_sizeof);
140 if (bytes > 0) { 141 if (bytes > 0) {
141 buf[bytes] = '\0'; 142 G.execname_cmpbuf[bytes] = '\0';
142 return strcmp(buf, execname) == 0; 143 return strcmp(execname, G.execname_cmpbuf) == 0;
143 } 144 }
144 return 0; 145 return 0;
145} 146}
@@ -194,9 +195,9 @@ static void check(int pid)
194 return; 195 return;
195 } 196 }
196 p = xmalloc(sizeof(*p)); 197 p = xmalloc(sizeof(*p));
197 p->next = found; 198 p->next = G.found_procs;
198 p->pid = pid; 199 p->pid = pid;
199 found = p; 200 G.found_procs = p;
200} 201}
201 202
202static void do_pidfile(void) 203static void do_pidfile(void)
@@ -266,13 +267,13 @@ static int do_stop(void)
266 bb_error_msg_and_die("internal error, please report"); 267 bb_error_msg_and_die("internal error, please report");
267 } 268 }
268 269
269 if (!found) { 270 if (!G.found_procs) {
270 if (!QUIET) 271 if (!QUIET)
271 printf("no %s found; none killed\n", what); 272 printf("no %s found; none killed\n", what);
272 killed = -1; 273 killed = -1;
273 goto ret; 274 goto ret;
274 } 275 }
275 for (p = found; p; p = p->next) { 276 for (p = G.found_procs; p; p = p->next) {
276 if (TEST || kill(p->pid, signal_nr) == 0) { 277 if (TEST || kill(p->pid, signal_nr) == 0) {
277 killed++; 278 killed++;
278 } else { 279 } else {
@@ -282,7 +283,7 @@ static int do_stop(void)
282 } 283 }
283 if (!QUIET && killed) { 284 if (!QUIET && killed) {
284 printf("stopped %s (pid", what); 285 printf("stopped %s (pid", what);
285 for (p = found; p; p = p->next) 286 for (p = G.found_procs; p; p = p->next)
286 if (p->pid) 287 if (p->pid)
287 printf(" %u", (unsigned)p->pid); 288 printf(" %u", (unsigned)p->pid);
288 puts(")"); 289 puts(")");
@@ -365,6 +366,10 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
365 startas = execname; 366 startas = execname;
366 if (!execname) /* in case -a is given and -x is not */ 367 if (!execname) /* in case -a is given and -x is not */
367 execname = startas; 368 execname = startas;
369 if (execname) {
370 G.execname_sizeof = strlen(execname) + 1;
371 G.execname_cmpbuf = xmalloc(G.execname_sizeof + 1);
372 }
368 373
369// IF_FEATURE_START_STOP_DAEMON_FANCY( 374// IF_FEATURE_START_STOP_DAEMON_FANCY(
370// if (retry_arg) 375// if (retry_arg)
@@ -386,9 +391,9 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
386 return (opt & OPT_OKNODO) ? 0 : (i <= 0); 391 return (opt & OPT_OKNODO) ? 0 : (i <= 0);
387 } 392 }
388 393
389 if (found) { 394 if (G.found_procs) {
390 if (!QUIET) 395 if (!QUIET)
391 printf("%s is already running\n%u\n", execname, (unsigned)found->pid); 396 printf("%s is already running\n%u\n", execname, (unsigned)G.found_procs->pid);
392 return !(opt & OPT_OKNODO); 397 return !(opt & OPT_OKNODO);
393 } 398 }
394 399
diff --git a/include/libbb.h b/include/libbb.h
index 72d6c7dc8..794e43889 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -339,7 +339,7 @@ void xmove_fd(int, int) FAST_FUNC;
339DIR *xopendir(const char *path) FAST_FUNC; 339DIR *xopendir(const char *path) FAST_FUNC;
340DIR *warn_opendir(const char *path) FAST_FUNC; 340DIR *warn_opendir(const char *path) FAST_FUNC;
341 341
342/* UNUSED: char *xmalloc_realpath(const char *path) FAST_FUNC RETURNS_MALLOC; */ 342char *xmalloc_realpath(const char *path) FAST_FUNC RETURNS_MALLOC;
343char *xmalloc_readlink(const char *path) FAST_FUNC RETURNS_MALLOC; 343char *xmalloc_readlink(const char *path) FAST_FUNC RETURNS_MALLOC;
344char *xmalloc_readlink_or_warn(const char *path) FAST_FUNC RETURNS_MALLOC; 344char *xmalloc_readlink_or_warn(const char *path) FAST_FUNC RETURNS_MALLOC;
345/* !RETURNS_MALLOC: it's a realloc-like function */ 345/* !RETURNS_MALLOC: it's a realloc-like function */
diff --git a/libbb/safe_gethostname.c b/libbb/safe_gethostname.c
index 7407fb782..e93254b2b 100644
--- a/libbb/safe_gethostname.c
+++ b/libbb/safe_gethostname.c
@@ -59,8 +59,12 @@ char* FAST_FUNC safe_gethostname(void)
59 */ 59 */
60char* FAST_FUNC safe_getdomainname(void) 60char* FAST_FUNC safe_getdomainname(void)
61{ 61{
62/* The field domainname of struct utsname is Linux specific. */
63#if defined(__linux__)
62 struct utsname uts; 64 struct utsname uts;
63
64 uname(&uts); 65 uname(&uts);
65 return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname)); 66 return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname));
67#else
68 return xstrdup("?");
69#endif
66} 70}
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 97751eb27..d8c8d02d5 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -21,6 +21,8 @@ int FAST_FUNC setsockopt_broadcast(int fd)
21{ 21{
22 return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1)); 22 return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1));
23} 23}
24
25#ifdef SO_BINDTODEVICE
24int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface) 26int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface)
25{ 27{
26 int r; 28 int r;
@@ -36,6 +38,14 @@ int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface)
36 bb_perror_msg("can't bind to interface %s", iface); 38 bb_perror_msg("can't bind to interface %s", iface);
37 return r; 39 return r;
38} 40}
41#else
42int FAST_FUNC setsockopt_bindtodevice(int fd UNUSED_PARAM,
43 const char *iface UNUSED_PARAM)
44{
45 bb_error_msg("SO_BINDTODEVICE is not supported on this system");
46 return -1;
47}
48#endif
39 49
40len_and_sockaddr* FAST_FUNC get_sock_lsa(int fd) 50len_and_sockaddr* FAST_FUNC get_sock_lsa(int fd)
41{ 51{
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index 8d232f16b..faa0e1646 100644
--- a/libbb/xreadlink.c
+++ b/libbb/xreadlink.c
@@ -100,18 +100,16 @@ char* FAST_FUNC xmalloc_readlink_or_warn(const char *path)
100 return buf; 100 return buf;
101} 101}
102 102
103/* UNUSED */
104#if 0
105char* FAST_FUNC xmalloc_realpath(const char *path) 103char* FAST_FUNC xmalloc_realpath(const char *path)
106{ 104{
107#if defined(__GLIBC__) && !defined(__UCLIBC__) 105#if defined(__GLIBC__) && !defined(__UCLIBC__)
108 /* glibc provides a non-standard extension */ 106 /* glibc provides a non-standard extension */
107 /* new: POSIX.1-2008 specifies this behavior as well */
109 return realpath(path, NULL); 108 return realpath(path, NULL);
110#else 109#else
111 char buf[PATH_MAX+1]; 110 char buf[PATH_MAX+1];
112 111
113 /* on error returns NULL (xstrdup(NULL) ==NULL) */ 112 /* on error returns NULL (xstrdup(NULL) == NULL) */
114 return xstrdup(realpath(path, buf)); 113 return xstrdup(realpath(path, buf));
115#endif 114#endif
116} 115}
117#endif
diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c
index dc7a0fcd2..ef5181226 100644
--- a/scripts/basic/docproc.c
+++ b/scripts/basic/docproc.c
@@ -79,7 +79,9 @@ void exec_kernel_doc(char **svec)
79{ 79{
80 pid_t pid; 80 pid_t pid;
81 int ret; 81 int ret;
82 char real_filename[PATH_MAX + 1]; 82 char *real_filename;
83 int rflen;
84
83 /* Make sure output generated so far are flushed */ 85 /* Make sure output generated so far are flushed */
84 fflush(stdout); 86 fflush(stdout);
85 switch(pid=fork()) { 87 switch(pid=fork()) {
@@ -87,10 +89,11 @@ void exec_kernel_doc(char **svec)
87 perror("fork"); 89 perror("fork");
88 exit(1); 90 exit(1);
89 case 0: 91 case 0:
90 memset(real_filename, 0, sizeof(real_filename)); 92 rflen = strlen(getenv("SRCTREE"));
91 strncat(real_filename, getenv("SRCTREE"), PATH_MAX); 93 rflen += strlen(KERNELDOCPATH KERNELDOC);
92 strncat(real_filename, KERNELDOCPATH KERNELDOC, 94 real_filename = alloca(rflen + 1);
93 PATH_MAX - strlen(real_filename)); 95 strcpy(real_filename, getenv("SRCTREE"));
96 strcat(real_filename, KERNELDOCPATH KERNELDOC);
94 execvp(real_filename, svec); 97 execvp(real_filename, svec);
95 fprintf(stderr, "exec "); 98 fprintf(stderr, "exec ");
96 perror(real_filename); 99 perror(real_filename);
@@ -166,11 +169,10 @@ void find_export_symbols(char * filename)
166 struct symfile *sym; 169 struct symfile *sym;
167 char line[MAXLINESZ]; 170 char line[MAXLINESZ];
168 if (filename_exist(filename) == NULL) { 171 if (filename_exist(filename) == NULL) {
169 char real_filename[PATH_MAX + 1]; 172 int rflen = strlen(getenv("SRCTREE")) + strlen(filename);
170 memset(real_filename, 0, sizeof(real_filename)); 173 char *real_filename = alloca(rflen + 1);
171 strncat(real_filename, getenv("SRCTREE"), PATH_MAX); 174 strcpy(real_filename, getenv("SRCTREE"));
172 strncat(real_filename, filename, 175 strcat(real_filename, filename);
173 PATH_MAX - strlen(real_filename));
174 sym = add_new_file(filename); 176 sym = add_new_file(filename);
175 fp = fopen(real_filename, "r"); 177 fp = fopen(real_filename, "r");
176 if (fp == NULL) 178 if (fp == NULL)
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 6d61044c4..bbb575cec 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -203,7 +203,7 @@ void clear_config(void)
203 */ 203 */
204void use_config(char *m, int slen) 204void use_config(char *m, int slen)
205{ 205{
206 char s[PATH_MAX]; 206 char *s = alloca(slen+1);
207 char *p; 207 char *p;
208 208
209 if (is_defined_config(m, slen)) 209 if (is_defined_config(m, slen))
@@ -310,7 +310,7 @@ void parse_dep_file(void *map, size_t len)
310 char *m = map; 310 char *m = map;
311 char *end = m + len; 311 char *end = m + len;
312 char *p; 312 char *p;
313 char s[PATH_MAX]; 313 char *s = alloca(len);
314 314
315 p = memchr(m, ':', len); 315 p = memchr(m, ':', len);
316 if (!p) { 316 if (!p) {
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 9365a12c2..4f83fbfa2 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -70,12 +70,13 @@ static char *conf_expand_value(const char *in)
70char *conf_get_default_confname(void) 70char *conf_get_default_confname(void)
71{ 71{
72 struct stat buf; 72 struct stat buf;
73 static char fullname[PATH_MAX+1]; 73 static char *fullname = NULL;
74 char *env, *name; 74 char *env, *name;
75 75
76 name = conf_expand_value(conf_defname); 76 name = conf_expand_value(conf_defname);
77 env = getenv(SRCTREE); 77 env = getenv(SRCTREE);
78 if (env) { 78 if (env) {
79 fullname = realloc(fullname, strlen(env) + strlen(name) + 2);
79 sprintf(fullname, "%s/%s", env, name); 80 sprintf(fullname, "%s/%s", env, name);
80 if (!stat(fullname, &buf)) 81 if (!stat(fullname, &buf))
81 return fullname; 82 return fullname;
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 647ec09f1..0c548bfc0 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -258,7 +258,7 @@ search_help[] = N_(
258 258
259static char buf[4096], *bufptr = buf; 259static char buf[4096], *bufptr = buf;
260static char input_buf[4096]; 260static char input_buf[4096];
261static char filename[PATH_MAX+1] = ".config"; 261static const char filename[] = ".config";
262static char *args[1024], **argptr = args; 262static char *args[1024], **argptr = args;
263static int indent; 263static int indent;
264static struct termios ios_org; 264static struct termios ios_org;
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index d839577ca..6a58b80d3 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -265,13 +265,14 @@ static void zconf_endhelp(void)
265 */ 265 */
266FILE *zconf_fopen(const char *name) 266FILE *zconf_fopen(const char *name)
267{ 267{
268 char *env, fullname[PATH_MAX+1]; 268 char *env;
269 FILE *f; 269 FILE *f;
270 270
271 f = fopen(name, "r"); 271 f = fopen(name, "r");
272 if (!f && name[0] != '/') { 272 if (!f && name[0] != '/') {
273 env = getenv(SRCTREE); 273 env = getenv(SRCTREE);
274 if (env) { 274 if (env) {
275 char *fullname = alloca(strlen(env) + strlen(name) + 2);
275 sprintf(fullname, "%s/%s", env, name); 276 sprintf(fullname, "%s/%s", env, name);
276 f = fopen(fullname, "r"); 277 f = fopen(fullname, "r");
277 } 278 }
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 0a7a79664..2007a4e02 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -14,8 +14,6 @@
14#define LKC_DIRECT_LINK 14#define LKC_DIRECT_LINK
15#include "lkc.h" 15#include "lkc.h"
16 16
17#include "zconf.hash.c"
18
19#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt) 17#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
20 18
21#define PRINTD 0x0001 19#define PRINTD 0x0001
@@ -99,6 +97,10 @@ static struct menu *current_menu, *current_entry;
99 menu_end_menu(); 97 menu_end_menu();
100} if_entry menu_entry choice_entry 98} if_entry menu_entry choice_entry
101 99
100%{
101#include "zconf.hash.c"
102%}
103
102%% 104%%
103input: stmt_list; 105input: stmt_list;
104 106
diff --git a/util-linux/umount.c b/util-linux/umount.c
index a4b2bd087..a19f86c3a 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -39,6 +39,10 @@
39# define MS_RELATIME (1 << 21) 39# define MS_RELATIME (1 << 21)
40#endif 40#endif
41#include "libbb.h" 41#include "libbb.h"
42#ifndef PATH_MAX
43# define PATH_MAX (4*1024)
44#endif
45
42 46
43#if defined(__dietlibc__) 47#if defined(__dietlibc__)
44/* 16.12.2006, Sampo Kellomaki (sampo@iki.fi) 48/* 16.12.2006, Sampo Kellomaki (sampo@iki.fi)
@@ -69,7 +73,7 @@ int umount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
69int umount_main(int argc UNUSED_PARAM, char **argv) 73int umount_main(int argc UNUSED_PARAM, char **argv)
70{ 74{
71 int doForce; 75 int doForce;
72 char *const path = xmalloc(PATH_MAX + 2); /* to save stack */ 76 char *const buf = xmalloc(PATH_MAX * 2 + 128); /* to save stack */
73 struct mntent me; 77 struct mntent me;
74 FILE *fp; 78 FILE *fp;
75 char *fstype = NULL; 79 char *fstype = NULL;
@@ -100,7 +104,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
100 if (opt & OPT_ALL) 104 if (opt & OPT_ALL)
101 bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file); 105 bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file);
102 } else { 106 } else {
103 while (getmntent_r(fp, &me, path, PATH_MAX)) { 107 while (getmntent_r(fp, &me, buf, PATH_MAX * 2 + 128)) {
104 /* Match fstype if passed */ 108 /* Match fstype if passed */
105 if (!match_fstype(&me, fstype)) 109 if (!match_fstype(&me, fstype))
106 continue; 110 continue;
@@ -124,10 +128,11 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
124 for (;;) { 128 for (;;) {
125 int curstat; 129 int curstat;
126 char *zapit = *argv; 130 char *zapit = *argv;
131 char *path;
127 132
128 // Do we already know what to umount this time through the loop? 133 // Do we already know what to umount this time through the loop?
129 if (m) 134 if (m)
130 safe_strncpy(path, m->dir, PATH_MAX); 135 path = xstrdup(m->dir);
131 // For umount -a, end of mtab means time to exit. 136 // For umount -a, end of mtab means time to exit.
132 else if (opt & OPT_ALL) 137 else if (opt & OPT_ALL)
133 break; 138 break;
@@ -136,10 +141,12 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
136 if (!zapit) 141 if (!zapit)
137 break; 142 break;
138 argv++; 143 argv++;
139 realpath(zapit, path); 144 path = xmalloc_realpath(zapit);
140 for (m = mtl; m; m = m->next) 145 if (path) {
141 if (!strcmp(path, m->dir) || !strcmp(path, m->device)) 146 for (m = mtl; m; m = m->next)
142 break; 147 if (strcmp(path, m->dir) == 0 || strcmp(path, m->device) == 0)
148 break;
149 }
143 } 150 }
144 // If we couldn't find this sucker in /etc/mtab, punt by passing our 151 // If we couldn't find this sucker in /etc/mtab, punt by passing our
145 // command line argument straight to the umount syscall. Otherwise, 152 // command line argument straight to the umount syscall. Otherwise,
@@ -181,9 +188,13 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
181 // Find next matching mtab entry for -a or umount /dev 188 // Find next matching mtab entry for -a or umount /dev
182 // Note this means that "umount /dev/blah" will unmount all instances 189 // Note this means that "umount /dev/blah" will unmount all instances
183 // of /dev/blah, not just the most recent. 190 // of /dev/blah, not just the most recent.
184 if (m) while ((m = m->next) != NULL) 191 if (m) {
185 if ((opt & OPT_ALL) || !strcmp(path, m->device)) 192 while ((m = m->next) != NULL)
186 break; 193 // NB: if m is non-NULL, path is non-NULL as well
194 if ((opt & OPT_ALL) || strcmp(path, m->device) == 0)
195 break;
196 }
197 free(path);
187 } 198 }
188 199
189 // Free mtab list if necessary 200 // Free mtab list if necessary
@@ -195,7 +206,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
195 free(mtl); 206 free(mtl);
196 mtl = m; 207 mtl = m;
197 } 208 }
198 free(path); 209 free(buf);
199 } 210 }
200 211
201 return status; 212 return status;