From: Karel Zak Date: Mon, 29 Jun 2009 23:13:42 +0000 (+0200) Subject: include: clean up _PATH_DEV_* macros X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c74c0daffffbecf1299055fb35908721bcc853b2;p=util-linux include: clean up _PATH_DEV_* macros Signed-off-by: Karel Zak --- diff --git a/include/pathnames.h b/include/pathnames.h index 0060a756..12170f9d 100644 --- a/include/pathnames.h +++ b/include/pathnames.h @@ -19,7 +19,6 @@ #undef _PATH_DEFPATH_ROOT #define _PATH_DEFPATH_ROOT "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" -#define _PATH_TTY "/dev/tty" #define _PATH_SECURETTY "/etc/securetty" #define _PATH_WTMPLOCK "/etc/wtmplock" @@ -94,6 +93,13 @@ #define _PATH_MOUNTED_LOCK _PATH_MOUNTED "~" #define _PATH_MOUNTED_TMP _PATH_MOUNTED ".tmp" +#ifndef _PATH_DEV +# define _PATH_DEV "/dev" +#endif + +#define _PATH_DEV_LOOP "/dev/loop" +#define _PATH_DEV_TTY "/dev/tty" + /* udev paths */ #define _PATH_DEV_BYLABEL "/dev/disk/by-label" #define _PATH_DEV_BYUUID "/dev/disk/by-uuid" diff --git a/login-utils/login.c b/login-utils/login.c index f3154259..7328edeb 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -378,7 +378,7 @@ main(int argc, char **argv) int ask, fflag, hflag, pflag, cnt, errsv; int quietlog, passwd_req; char *domain, *ttyn; - char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; + char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_DEV_TTY) + 10]; char *termenv; char *childArgv[10]; char *buff; @@ -499,7 +499,7 @@ main(int argc, char **argv) if (ttyn == NULL || *ttyn == '\0') { /* no snprintf required - see definition of tname */ - sprintf(tname, "%s??", _PATH_TTY); + snprintf(tname, sizeof(tname), "%s??", _PATH_DEV_TTY); ttyn = tname; } diff --git a/misc-utils/script.c b/misc-utils/script.c index 12ea43a8..b877c312 100644 --- a/misc-utils/script.c +++ b/misc-utils/script.c @@ -371,7 +371,7 @@ doshell() { #if 0 int t; - t = open(_PATH_TTY, O_RDWR); + t = open(_PATH_DEV_TTY, O_RDWR); if (t >= 0) { (void) ioctl(t, TIOCNOTTY, (char *)0); (void) close(t); diff --git a/mount/lomount.c b/mount/lomount.c index f0f81ed6..c6e0c929 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -60,8 +60,6 @@ loop_info64_to_old(const struct loop_info64 *info64, struct loop_info *info) return 0; } -#define DEV_LOOP_PATH "/dev/loop" -#define DEV_PATH "/dev" #define LOOPMAJOR 7 #define NLOOPS_DEFAULT 8 /* /dev/loop[0-7] */ @@ -143,10 +141,10 @@ looplist_open(struct looplist *ll, int flag) ll->flag = flag; ll->ncur = -1; - if (stat(DEV_PATH, &st) == -1 || (!S_ISDIR(st.st_mode))) + if (stat(_PATH_DEV, &st) == -1 || (!S_ISDIR(st.st_mode))) return -1; /* /dev doesn't exist */ - if (stat(DEV_LOOP_PATH, &st) == 0 && S_ISDIR(st.st_mode)) + if (stat(_PATH_DEV_LOOP, &st) == 0 && S_ISDIR(st.st_mode)) ll->flag |= LLFLG_SUBDIR; /* /dev/loop/ exists */ if ((ll->flag & LLFLG_USEDONLY) && @@ -179,8 +177,8 @@ looplist_open_dev(struct looplist *ll, int lnum) /* create a full device path */ snprintf(ll->name, sizeof(ll->name), ll->flag & LLFLG_SUBDIR ? - DEV_LOOP_PATH "/%d" : - DEV_PATH "/loop%d", + _PATH_DEV_LOOP "/%d" : + _PATH_DEV "/loop%d", lnum); fd = open(ll->name, O_RDONLY); @@ -331,8 +329,8 @@ looplist_next(struct looplist *ll) */ if (!ll->minors) { ll->nminors = (ll->flag & LLFLG_SUBDIR) ? - loop_scandir(DEV_LOOP_PATH, &ll->minors, 0) : - loop_scandir(DEV_PATH, &ll->minors, 1); + loop_scandir(_PATH_DEV_LOOP, &ll->minors, 0) : + loop_scandir(_PATH_DEV, &ll->minors, 1); ll->ncur = -1; } for (++ll->ncur; ll->ncur < ll->nminors; ll->ncur++) { diff --git a/mount/umount.c b/mount/umount.c index 0e5934fd..a695f0c6 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -14,6 +14,7 @@ #include "mount_constants.h" #include "sundries.h" #include "getusername.h" +#include "pathnames.h" #include "lomount.h" #include "loop.h" #include "fstab.h" @@ -445,7 +446,8 @@ is_valid_loop(struct mntentchn *mc, struct mntentchn *fs) char *p; /* check if it begins with /dev/loop */ - if (strncmp(mc->m.mnt_fsname, "/dev/loop", 9)) + if (strncmp(mc->m.mnt_fsname, _PATH_DEV_LOOP, + sizeof(_PATH_DEV_LOOP) - 1)) return 0; /* check for loop option in fstab */ diff --git a/tests/expected/paths/built-in b/tests/expected/paths/built-in index 318f44e5..51372de3 100644 --- a/tests/expected/paths/built-in +++ b/tests/expected/paths/built-in @@ -1,6 +1,7 @@ _PATH_DEFPATH /usr/local/bin:/bin:/usr/bin _PATH_DEFPATH_ROOT /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin - _PATH_TTY /dev/tty + _PATH_DEV_TTY /dev/tty + _PATH_DEV_LOOP /dev/loop _PATH_SECURETTY /etc/securetty _PATH_WTMPLOCK /etc/wtmplock _PATH_HUSHLOGIN .hushlogin diff --git a/tests/helpers/test_pathnames.c b/tests/helpers/test_pathnames.c index 1accedec..5cc6efd7 100644 --- a/tests/helpers/test_pathnames.c +++ b/tests/helpers/test_pathnames.c @@ -33,7 +33,8 @@ struct hlpPath paths[] = { DEF_HLPPATH(_PATH_DEFPATH), DEF_HLPPATH(_PATH_DEFPATH_ROOT), - DEF_HLPPATH(_PATH_TTY), + DEF_HLPPATH(_PATH_DEV_TTY), + DEF_HLPPATH(_PATH_DEV_LOOP), DEF_HLPPATH(_PATH_SECURETTY), DEF_HLPPATH(_PATH_WTMPLOCK), DEF_HLPPATH(_PATH_HUSHLOGIN),