From a88057d9a329c11a5d4eaf7e15ce25b09be800e5 Mon Sep 17 00:00:00 2001 From: Tom Prince Date: Thu, 14 May 2009 22:43:02 -0400 Subject: cal: uClibc has langinfo.h but not _NL_TIME_WEEK_1STDAY. Signed-off-by: Tom Prince --- misc-utils/cal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc-utils') diff --git a/misc-utils/cal.c b/misc-utils/cal.c index f2d52e8c..a8534b8c 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -291,7 +291,7 @@ main(int argc, char **argv) { * the locale database, which can be overridden with the * -s (Sunday) or -m (Monday) options. */ -#ifdef HAVE_LANGINFO_H +#if HAVE_DECL__NL_TIME_WEEK_1STDAY /* * You need to use 2 locale variables to get the first day of the week. * This is needed to support first_weekday=2 and first_workday=1 for -- cgit v1.2.3 From 0140c3972bd68ccfe3a418a0c5c5b4117d6e931c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 21 May 2009 16:02:42 +0200 Subject: uuidgen: new command (from e2fsprogs) Signed-off-by: Karel Zak --- misc-utils/.gitignore | 1 + misc-utils/Makefile.am | 8 +++++- misc-utils/uuidgen.1 | 62 ++++++++++++++++++++++++++++++++++++++++ misc-utils/uuidgen.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 misc-utils/uuidgen.1 create mode 100644 misc-utils/uuidgen.c (limited to 'misc-utils') diff --git a/misc-utils/.gitignore b/misc-utils/.gitignore index 122b1920..ddb44213 100644 --- a/misc-utils/.gitignore +++ b/misc-utils/.gitignore @@ -12,3 +12,4 @@ setterm whereis kill write +uuidgen diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index 40610c14..781e5d2e 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -17,6 +17,13 @@ CLEANFILES = chkdupexe dist_man_MANS = cal.1 chkdupexe.1 ddate.1 logger.1 look.1 mcookie.1 \ namei.1 script.1 whereis.1 scriptreplay.1 +if BUILD_LIBUUID +usrbinexec_PROGRAMS += uuidgen +dist_man_MANS += uuidgen.1 +uuidgen_LDADD = $(ul_libuuid_la) +uuidgen_CFLAGS = -I$(ul_libuuid_srcdir) +endif + if HAVE_TINFO cal_LDADD = -ltinfo @NCURSES_LIBS@ else @@ -63,7 +70,6 @@ endif EXTRA_DIST += README.reset reset.033c if BUILD_WRITE - usrbinexec_PROGRAMS += write dist_man_MANS += write.1 write_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS) diff --git a/misc-utils/uuidgen.1 b/misc-utils/uuidgen.1 new file mode 100644 index 00000000..13b13c42 --- /dev/null +++ b/misc-utils/uuidgen.1 @@ -0,0 +1,62 @@ +.\" Copyright 1999 Andreas Dilger (adilger@enel.ucalgary.ca) +.\" +.\" This man page was created for libuuid.so.1.1 from e2fsprogs-1.14. +.\" +.\" This file may be copied under the terms of the GNU Public License. +.\" +.\" Created Wed Mar 10 17:42:12 1999, Andreas Dilger +.TH UUIDGEN 1 "May 2009" "Linux" +.SH NAME +uuidgen \- command\-line utility to create a new UUID value +.SH SYNOPSIS +.B uuidgen +[ +.B \-r +| +.B \-t +] +.SH DESCRIPTION +The +.B uuidgen +program creates (and prints) +a new universally unique identifier (UUID) using the +.BR libuuid (3) +library. The new UUID can reasonably be considered unique among +all UUIDs created on the local system, +and among UUIDs created on other systems in the past +and in the future. +.PP +There are two types of UUID's which +.B uuidgen +can generate: time-based UUID's and random-based UUID's. By +default +.B uuidgen +will generate a random-based UUID if a high-quality random number +generator is present. Otherwise, it will chose a time-based UUID. It +is possible to force the generation of one of these two +UUID types by using the +.B \-r +or +.B \-t +options. +.SH OPTIONS +.TP +.B \-r +Generate a random-based UUID. This method creates a UUID consisting mostly +of random bits. It requires that the operating system have a high +quality random number generator, such as +.IR /dev/random . +.TP +.B \-t +Generate a time-based UUID. This method creates a UUID based on the system +clock plus the system's ethernet hardware address, if present. +.SH "CONFORMING TO" +OSF DCE 1.1 +.SH AUTHOR +.B uuidgen +was written by Andreas Dilger for libuuid. +.SH AVAILABILITY +The uuidgen command is part of the util-linux-ng package and is available from +ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. +.SH "SEE ALSO" +.BR libuuid (3) diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c new file mode 100644 index 00000000..3cf6ec91 --- /dev/null +++ b/misc-utils/uuidgen.c @@ -0,0 +1,77 @@ +/* + * gen_uuid.c --- generate a DCE-compatible uuid + * + * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_GETOPT_H +#include +#else +extern int getopt(int argc, char * const argv[], const char *optstring); +extern char *optarg; +extern int optind; +#endif + +#include "uuid.h" +#include "nls.h" + +#define DO_TYPE_TIME 1 +#define DO_TYPE_RANDOM 2 + +static void usage(const char *progname) +{ + fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname); + exit(1); +} + +int +main (int argc, char *argv[]) +{ + int c; + int do_type = 0; + char str[37]; + uuid_t uu; + + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + while ((c = getopt (argc, argv, "tr")) != EOF) + switch (c) { + case 't': + do_type = DO_TYPE_TIME; + break; + case 'r': + do_type = DO_TYPE_RANDOM; + break; + default: + usage(argv[0]); + } + + switch (do_type) { + case DO_TYPE_TIME: + uuid_generate_time(uu); + break; + case DO_TYPE_RANDOM: + uuid_generate_random(uu); + break; + default: + uuid_generate(uu); + break; + } + + uuid_unparse(uu, str); + + printf("%s\n", str); + + return 0; +} -- cgit v1.2.3 From 69045d3dbaf95ae73eda90bc20234b6a520dab0f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 22 May 2009 09:08:43 +0200 Subject: uuidd: new command (UUID daemon from e2fsprogs) Signed-off-by: Karel Zak --- configure.ac | 2 + example.files/uuidd.rc | 55 +++++ misc-utils/.gitignore | 1 + misc-utils/Makefile.am | 6 + misc-utils/uuidd.8 | 96 ++++++++ misc-utils/uuidd.c | 572 ++++++++++++++++++++++++++++++++++++++++++++ shlibs/uuid/src/Makefile.am | 2 +- shlibs/uuid/src/uuid.sym | 6 + 8 files changed, 739 insertions(+), 1 deletion(-) create mode 100644 example.files/uuidd.rc create mode 100644 misc-utils/uuidd.8 create mode 100644 misc-utils/uuidd.c (limited to 'misc-utils') diff --git a/configure.ac b/configure.ac index 0b3cf359..e9a89199 100644 --- a/configure.ac +++ b/configure.ac @@ -137,6 +137,8 @@ AC_CHECK_FUNCS( getdtablesize \ getrlimit \ srandom \ + setresgid \ + setresuid \ inotify_init \ prctl \ __secure_getenv \ diff --git a/example.files/uuidd.rc b/example.files/uuidd.rc new file mode 100644 index 00000000..d35645a1 --- /dev/null +++ b/example.files/uuidd.rc @@ -0,0 +1,55 @@ +#! /bin/sh -e +### BEGIN INIT INFO +# Provides: uuidd +# Required-Start: $time $local_fs +# Required-Stop: $time $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: uuidd daemon +# Description: Init script for the uuid generation daemon +### END INIT INFO +# +# Author: "Theodore Ts'o" +# +set -e + +PATH=/bin:/usr/bin:/sbin:/usr/sbin +DAEMON=/usr/sbin/uuidd +PIDFILE=/var/run/uuidd/uuidd.pid + +test -x $DAEMON || exit 0 + +. /lib/lsb/init-functions + +case "$1" in + start) + log_daemon_msg "Starting uuid generator" "uuidd" + start_daemon -p $PIDFILE $DAEMON + log_end_msg $? + ;; + stop) + log_daemon_msg "Stopping uuidd generator" "uuidd" + killproc -p $PIDFILE $DAEMON + log_end_msg $? + ;; + status) + if pidofproc -p $PIDFILE $DAEMON >& /dev/null ; then + echo "$DAEMON is running"; + exit 0; + else + echo "$DAEMON is NOT running"; + if test -f /var/run/uuidd.pid; then exit 2; fi + exit 3; + fi + ;; + force-reload|restart) + $0 stop + $0 start + ;; + *) + echo "Usage: /etc/init.d/uuidd {start|stop|restart|force-reload}" + exit 1 + ;; +esac + +exit 0 diff --git a/misc-utils/.gitignore b/misc-utils/.gitignore index ddb44213..e58c9301 100644 --- a/misc-utils/.gitignore +++ b/misc-utils/.gitignore @@ -13,3 +13,4 @@ whereis kill write uuidgen +uuidd diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index 781e5d2e..087e4a1b 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -3,6 +3,7 @@ include $(top_srcdir)/config/include-Makefile.am EXTRA_DIST = README.flushb bin_PROGRAMS = +usrsbinexec_PROGRAMS = usrbinexec_PROGRAMS = cal ddate logger look mcookie \ namei script whereis scriptreplay @@ -22,6 +23,11 @@ usrbinexec_PROGRAMS += uuidgen dist_man_MANS += uuidgen.1 uuidgen_LDADD = $(ul_libuuid_la) uuidgen_CFLAGS = -I$(ul_libuuid_srcdir) + +usrsbinexec_PROGRAMS += uuidd +dist_man_MANS += uuidd.8 +uuidd_LDADD = $(ul_libuuid_la) +uuidd_CFLAGS = -I$(ul_libuuid_srcdir) endif if HAVE_TINFO diff --git a/misc-utils/uuidd.8 b/misc-utils/uuidd.8 new file mode 100644 index 00000000..ae033eaf --- /dev/null +++ b/misc-utils/uuidd.8 @@ -0,0 +1,96 @@ +.\" -*- nroff -*- +.\" Copyright 2007 by Theodore Ts'o. All Rights Reserved. +.\" This file may be copied under the terms of the GNU Public License. +.\" +.TH UUIDD 8 "May 2009" "Linux" +.SH NAME +uuidd \- UUID generation daemon +.SH SYNOPSIS +.B uuidd +[ +.B \-d +] +[ +.B \-p +.I pidfile +] +[ +.B \-s +.I socketpath +] +[ +.B \-T +.I timeout +] + +.B uuidd +[ +.B \-r +| +.B \-t +] +[ +.B \-n +.I number +] +[ +.B \-s +.I socketpath +] + +.B uuidd \-k +.SH DESCRIPTION +The +.B uuidd +daemon is used by the UUID library to generate +universally unique identifiers (UUIDs), especially time-based UUID's +in a secure and guaranteed-unique fashion, even in the face of large +numbers of threads trying to grab UUID's running on different CPU's. +.SH OPTIONS +.TP +.B \-d +Run +.B uuidd +in debugging mode. This prevents uuidd from running as a daemon. +.TP +.B \-k +If a currently uuidd daemon is running, kill it. +.TP +.BI \-n " number" +When issuing a test request to a running uuidd, request a bulk response +of +.I number +UUID's. +.TP +.BI \-p " pidfile" +Specify the pathname where the pid file should be written. By default, +the pid file is written to /var/lib/libuuid/uuidd.pid. +.TP +.BI \-s " socketpath" +Specify the pathname used for the unix-domain socket used by uuidd. By +default, the pathname used is /var/lib/libuuid/request. This is primarily +for debugging purposes, since the pathname is hard-coded in the libuuid +library. +.TP +.B \-r +Test uuidd by trying to connect to a running uuidd daemon and +request it to return a random-based UUID. +.TP +.B \-t +Test uuidd by trying to connect to a running uuidd daemon and +request it to return a time-based UUID. +.TP +.BI \-T " timeout" +Specify a timeout for uuidd. If specified, then uuidd will exit after +.I timeout +seconds of inactivity. +.SH AUTHOR +The +.B uuidd +daemon was written by Theodore Ts'o . +.SH AVAILABILITY +uuidd is part of the util-linux-ng package and is available from +ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. +.SH "SEE ALSO" +.BR libuuid (3), +.BR uuidgen (1) diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c new file mode 100644 index 00000000..5e597833 --- /dev/null +++ b/misc-utils/uuidd.c @@ -0,0 +1,572 @@ +/* + * uuidd.c --- UUID-generation daemon + * + * Copyright (C) 2007 Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_GETOPT_H +#include +#else +extern int getopt(int argc, char * const argv[], const char *optstring); +extern char *optarg; +extern int optind; +#endif + +#include "uuid.h" +#include "uuidd.h" + +#include "nls.h" + +#ifdef __GNUC__ +#define CODE_ATTR(x) __attribute__(x) +#else +#define CODE_ATTR(x) +#endif + +static void usage(const char *progname) +{ + fprintf(stderr, _("Usage: %s [-d] [-p pidfile] [-s socketpath] " + "[-T timeout]\n"), progname); + fprintf(stderr, _(" %s [-r|t] [-n num] [-s socketpath]\n"), + progname); + fprintf(stderr, _(" %s -k\n"), progname); + exit(1); +} + +static void die(const char *msg) +{ + perror(msg); + exit(1); +} + +static void create_daemon(void) +{ + pid_t pid; + uid_t euid; + + pid = fork(); + if (pid == -1) { + perror("fork"); + exit(1); + } else if (pid != 0) { + exit(0); + } + + close(0); + close(1); + close(2); + open("/dev/null", O_RDWR); + open("/dev/null", O_RDWR); + open("/dev/null", O_RDWR); + + if (chdir("/")) {} /* Silence warn_unused_result warning */ + (void) setsid(); + euid = geteuid(); + if (setreuid(euid, euid) < 0) + die("setreuid"); +} + +static int read_all(int fd, char *buf, size_t count) +{ + ssize_t ret; + int c = 0; + + memset(buf, 0, count); + while (count > 0) { + ret = read(fd, buf, count); + if (ret < 0) { + if ((errno == EAGAIN) || (errno == EINTR)) + continue; + return -1; + } + count -= ret; + buf += ret; + c += ret; + } + return c; +} + +static int write_all(int fd, char *buf, size_t count) +{ + ssize_t ret; + int c = 0; + + while (count > 0) { + ret = write(fd, buf, count); + if (ret < 0) { + if ((errno == EAGAIN) || (errno == EINTR)) + continue; + return -1; + } + count -= ret; + buf += ret; + c += ret; + } + return c; +} + +static const char *cleanup_pidfile, *cleanup_socket; + +static void terminate_intr(int signo CODE_ATTR((unused))) +{ + (void) unlink(cleanup_pidfile); + if (cleanup_socket) + (void) unlink(cleanup_socket); + exit(0); +} + +static int call_daemon(const char *socket_path, int op, char *buf, + int buflen, int *num, const char **err_context) +{ + char op_buf[8]; + int op_len; + int s; + ssize_t ret; + int32_t reply_len = 0; + struct sockaddr_un srv_addr; + + if (((op == 4) || (op == 5)) && !num) { + if (err_context) + *err_context = _("bad arguments"); + errno = EINVAL; + return -1; + } + + if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + if (err_context) + *err_context = _("socket"); + return -1; + } + + srv_addr.sun_family = AF_UNIX; + strncpy(srv_addr.sun_path, socket_path, sizeof(srv_addr.sun_path)); + srv_addr.sun_path[sizeof(srv_addr.sun_path)-1] = '\0'; + + if (connect(s, (const struct sockaddr *) &srv_addr, + sizeof(struct sockaddr_un)) < 0) { + if (err_context) + *err_context = _("connect"); + close(s); + return -1; + } + + if (op == 5) { + if ((*num)*16 > buflen-4) + *num = (buflen-4) / 16; + } + op_buf[0] = op; + op_len = 1; + if ((op == 4) || (op == 5)) { + memcpy(op_buf+1, num, sizeof(int)); + op_len += sizeof(int); + } + + ret = write_all(s, op_buf, op_len); + if (ret < op_len) { + if (err_context) + *err_context = _("write"); + close(s); + return -1; + } + + ret = read_all(s, (char *) &reply_len, sizeof(reply_len)); + if (ret < 0) { + if (err_context) + *err_context = _("read count"); + close(s); + return -1; + } + if (reply_len < 0 || reply_len > buflen) { + if (err_context) + *err_context = _("bad response length"); + close(s); + return -1; + } + ret = read_all(s, (char *) buf, reply_len); + + if ((ret > 0) && (op == 4)) { + if (reply_len >= (int) (16+sizeof(int))) + memcpy(buf+16, num, sizeof(int)); + else + *num = -1; + } + if ((ret > 0) && (op == 5)) { + if (*num >= (int) sizeof(int)) + memcpy(buf, num, sizeof(int)); + else + *num = -1; + } + + close(s); + + return ret; +} + +static void server_loop(const char *socket_path, const char *pidfile_path, + int debug, int timeout, int quiet) +{ + struct sockaddr_un my_addr, from_addr; + struct flock fl; + socklen_t fromlen; + int32_t reply_len = 0; + uuid_t uu; + mode_t save_umask; + char reply_buf[1024], *cp; + char op, str[37]; + int i, s, ns, len, num; + int fd_pidfile, ret; + + fd_pidfile = open(pidfile_path, O_CREAT | O_RDWR, 0664); + if (fd_pidfile < 0) { + if (!quiet) + fprintf(stderr, "Failed to open/create %s: %s\n", + pidfile_path, strerror(errno)); + exit(1); + } + cleanup_pidfile = pidfile_path; + cleanup_socket = 0; + signal(SIGALRM, terminate_intr); + alarm(30); + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + fl.l_pid = 0; + while (fcntl(fd_pidfile, F_SETLKW, &fl) < 0) { + if ((errno == EAGAIN) || (errno == EINTR)) + continue; + if (!quiet) + fprintf(stderr, "Failed to lock %s: %s\n", + pidfile_path, strerror(errno)); + exit(1); + } + ret = call_daemon(socket_path, 0, reply_buf, sizeof(reply_buf), 0, 0); + if (ret > 0) { + if (!quiet) + printf(_("uuidd daemon already running at pid %s\n"), + reply_buf); + exit(1); + } + alarm(0); + + if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + if (!quiet) + fprintf(stderr, _("Couldn't create unix stream " + "socket: %s"), strerror(errno)); + exit(1); + } + + /* + * Create the address we will be binding to. + */ + my_addr.sun_family = AF_UNIX; + strncpy(my_addr.sun_path, socket_path, sizeof(my_addr.sun_path)); + my_addr.sun_path[sizeof(my_addr.sun_path)-1] = '\0'; + (void) unlink(socket_path); + save_umask = umask(0); + if (bind(s, (const struct sockaddr *) &my_addr, + sizeof(struct sockaddr_un)) < 0) { + if (!quiet) + fprintf(stderr, + _("Couldn't bind unix socket %s: %s\n"), + socket_path, strerror(errno)); + exit(1); + } + (void) umask(save_umask); + + if (listen(s, 5) < 0) { + if (!quiet) + fprintf(stderr, _("Couldn't listen on unix " + "socket %s: %s\n"), socket_path, + strerror(errno)); + exit(1); + } + + cleanup_socket = socket_path; + if (!debug) + create_daemon(); + signal(SIGHUP, terminate_intr); + signal(SIGINT, terminate_intr); + signal(SIGTERM, terminate_intr); + signal(SIGALRM, terminate_intr); + signal(SIGPIPE, SIG_IGN); + + sprintf(reply_buf, "%8d\n", getpid()); + if (ftruncate(fd_pidfile, 0)) {} /* Silence warn_unused_result */ + write_all(fd_pidfile, reply_buf, strlen(reply_buf)); + if (fd_pidfile > 1) + close(fd_pidfile); /* Unlock the pid file */ + + while (1) { + fromlen = sizeof(from_addr); + if (timeout > 0) + alarm(timeout); + ns = accept(s, (struct sockaddr *) &from_addr, &fromlen); + alarm(0); + if (ns < 0) { + if ((errno == EAGAIN) || (errno == EINTR)) + continue; + perror("accept"); + exit(1); + } + len = read(ns, &op, 1); + if (len != 1) { + if (len < 0) + perror("read"); + else + printf(_("Error reading from client, " + "len = %d\n"), len); + goto shutdown_socket; + } + if ((op == 4) || (op == 5)) { + if (read_all(ns, (char *) &num, sizeof(num)) != 4) + goto shutdown_socket; + if (debug) + printf(_("operation %d, incoming num = %d\n"), + op, num); + } else if (debug) + printf("operation %d\n", op); + + switch(op) { + case UUIDD_OP_GETPID: + sprintf(reply_buf, "%d", getpid()); + reply_len = strlen(reply_buf)+1; + break; + case UUIDD_OP_GET_MAXOP: + sprintf(reply_buf, "%d", UUIDD_MAX_OP); + reply_len = strlen(reply_buf)+1; + break; + case UUIDD_OP_TIME_UUID: + num = 1; + uuid__generate_time(uu, &num); + if (debug) { + uuid_unparse(uu, str); + printf(_("Generated time UUID: %s\n"), str); + } + memcpy(reply_buf, uu, sizeof(uu)); + reply_len = sizeof(uu); + break; + case UUIDD_OP_RANDOM_UUID: + num = 1; + uuid__generate_random(uu, &num); + if (debug) { + uuid_unparse(uu, str); + printf(_("Generated random UUID: %s\n"), str); + } + memcpy(reply_buf, uu, sizeof(uu)); + reply_len = sizeof(uu); + break; + case UUIDD_OP_BULK_TIME_UUID: + uuid__generate_time(uu, &num); + if (debug) { + uuid_unparse(uu, str); + printf(_("Generated time UUID %s and %d " + "following\n"), str, num); + } + memcpy(reply_buf, uu, sizeof(uu)); + reply_len = sizeof(uu); + memcpy(reply_buf+reply_len, &num, sizeof(num)); + reply_len += sizeof(num); + break; + case UUIDD_OP_BULK_RANDOM_UUID: + if (num < 0) + num = 1; + if (num > 1000) + num = 1000; + if (num*16 > (int) (sizeof(reply_buf)-sizeof(num))) + num = (sizeof(reply_buf)-sizeof(num)) / 16; + uuid__generate_random((unsigned char *) reply_buf + + sizeof(num), &num); + if (debug) { + printf(_("Generated %d UUID's:\n"), num); + for (i=0, cp=reply_buf+sizeof(num); + i < num; i++, cp+=16) { + uuid_unparse((unsigned char *)cp, str); + printf("\t%s\n", str); + } + } + reply_len = (num*16) + sizeof(num); + memcpy(reply_buf, &num, sizeof(num)); + break; + default: + if (debug) + printf(_("Invalid operation %d\n"), op); + goto shutdown_socket; + } + write_all(ns, (char *) &reply_len, sizeof(reply_len)); + write_all(ns, reply_buf, reply_len); + shutdown_socket: + close(ns); + } +} + +int main(int argc, char **argv) +{ + const char *socket_path = UUIDD_SOCKET_PATH; + const char *pidfile_path = UUIDD_PIDFILE_PATH; + const char *err_context; + char buf[1024], *cp; + char str[37], *tmp; + uuid_t uu; + uid_t uid; + gid_t gid; + int i, c, ret; + int debug = 0, do_type = 0, do_kill = 0, num = 0; + int timeout = 0, quiet = 0, drop_privs = 0; + + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + while ((c = getopt (argc, argv, "dkn:qp:s:tT:r")) != EOF) { + switch (c) { + case 'd': + debug++; + drop_privs = 1; + break; + case 'k': + do_kill++; + drop_privs = 1; + break; + case 'n': + num = strtol(optarg, &tmp, 0); + if ((num < 0) || *tmp) { + fprintf(stderr, _("Bad number: %s\n"), optarg); + exit(1); + } + case 'p': + pidfile_path = optarg; + drop_privs = 1; + break; + case 'q': + quiet++; + break; + case 's': + socket_path = optarg; + drop_privs = 1; + break; + case 't': + do_type = UUIDD_OP_TIME_UUID; + drop_privs = 1; + break; + case 'T': + timeout = strtol(optarg, &tmp, 0); + if ((timeout < 0) || *tmp) { + fprintf(stderr, _("Bad number: %s\n"), optarg); + exit(1); + } + break; + case 'r': + do_type = UUIDD_OP_RANDOM_UUID; + drop_privs = 1; + break; + default: + usage(argv[0]); + } + } + uid = getuid(); + if (uid && drop_privs) { + gid = getgid(); +#ifdef HAVE_SETRESGID + if (setresgid(gid, gid, gid) < 0) + die("setresgid"); +#else + if (setregid(gid, gid) < 0) + die("setregid"); +#endif + +#ifdef HAVE_SETRESUID + if (setresuid(uid, uid, uid) < 0) + die("setresuid"); +#else + if (setreuid(uid, uid) < 0) + die("setreuid"); +#endif + } + if (num && do_type) { + ret = call_daemon(socket_path, do_type+2, buf, + sizeof(buf), &num, &err_context); + if (ret < 0) { + printf(_("Error calling uuidd daemon (%s): %s\n"), + err_context, strerror(errno)); + exit(1); + } + if (do_type == UUIDD_OP_TIME_UUID) { + if (ret != sizeof(uu) + sizeof(num)) + goto unexpected_size; + + uuid_unparse((unsigned char *) buf, str); + + printf(_("%s and subsequent %d UUID's\n"), str, num); + } else { + printf(_("List of UUID's:\n")); + cp = buf + 4; + if (ret != (int) (sizeof(num) + num*sizeof(uu))) + goto unexpected_size; + for (i=0; i < num; i++, cp+=16) { + uuid_unparse((unsigned char *) cp, str); + printf("\t%s\n", str); + } + } + exit(0); + } + if (do_type) { + ret = call_daemon(socket_path, do_type, (char *) &uu, + sizeof(uu), 0, &err_context); + if (ret < 0) { + printf(_("Error calling uuidd daemon (%s): %s\n"), + err_context, strerror(errno)); + exit(1); + } + if (ret != sizeof(uu)) { + unexpected_size: + printf(_("Unexpected reply length from server %d\n"), + ret); + exit(1); + } + uuid_unparse(uu, str); + + printf("%s\n", str); + exit(0); + } + + if (do_kill) { + ret = call_daemon(socket_path, 0, buf, sizeof(buf), 0, 0); + if ((ret > 0) && ((do_kill = atoi((char *) buf)) > 0)) { + ret = kill(do_kill, SIGTERM); + if (ret < 0) { + if (!quiet) + fprintf(stderr, + _("Couldn't kill uuidd running " + "at pid %d: %s\n"), do_kill, + strerror(errno)); + exit(1); + } + if (!quiet) + printf(_("Killed uuidd running at pid %d\n"), + do_kill); + } + exit(0); + } + + server_loop(socket_path, pidfile_path, debug, timeout, quiet); + return 0; +} diff --git a/shlibs/uuid/src/Makefile.am b/shlibs/uuid/src/Makefile.am index cfbb004d..cc2ee7df 100644 --- a/shlibs/uuid/src/Makefile.am +++ b/shlibs/uuid/src/Makefile.am @@ -13,7 +13,7 @@ uuidinc_HEADERS = uuid.h lib_LTLIBRARIES = libuuid.la libuuid_la_SOURCES = clear.c compare.c copy.c gen_uuid.c \ isnull.c pack.c parse.c unpack.c unparse.c uuidd.h \ - uuid.h uuidP.h uuid_time.c $(uuidinc_HEADERS) + uuidd.h uuidP.h uuid_time.c $(uuidinc_HEADERS) libuuid_la_DEPENDENCIES = $(libuuid_la_LIBADD) uuid.sym diff --git a/shlibs/uuid/src/uuid.sym b/shlibs/uuid/src/uuid.sym index 591319aa..05d9f393 100644 --- a/shlibs/uuid/src/uuid.sym +++ b/shlibs/uuid/src/uuid.sym @@ -22,6 +22,12 @@ global: uuid_time; uuid_type; uuid_variant; + + /* uuid__* this is not part of the official API, this is + * uuidd (uuid daemon) specific stuff. Hell. + */ + uuid__generate_time; + uuid__generate_random; local: *; }; -- cgit v1.2.3 From 18c3e4168cab2d084ad2f82c3f37e398c21b8b0a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Sun, 28 Jun 2009 22:52:29 +0200 Subject: build-sys: fix --disable-uuidd Signed-off-by: Karel Zak --- misc-utils/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'misc-utils') diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index 087e4a1b..26fa22df 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -23,12 +23,13 @@ usrbinexec_PROGRAMS += uuidgen dist_man_MANS += uuidgen.1 uuidgen_LDADD = $(ul_libuuid_la) uuidgen_CFLAGS = -I$(ul_libuuid_srcdir) - +if BUILD_UUIDD usrsbinexec_PROGRAMS += uuidd dist_man_MANS += uuidd.8 uuidd_LDADD = $(ul_libuuid_la) uuidd_CFLAGS = -I$(ul_libuuid_srcdir) endif +endif if HAVE_TINFO cal_LDADD = -ltinfo @NCURSES_LIBS@ -- cgit v1.2.3 From a0fca6a75228794279e54980d646b5bb4a75eac1 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 29 Jun 2009 15:59:48 +0200 Subject: uuidd: move uuidd files from /var/lib/libuuid to /var/run/uuidd Reported-by: Kay Sievers Signed-off-by: Karel Zak --- misc-utils/uuidd.8 | 4 ++-- shlibs/uuid/src/uuidd.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'misc-utils') diff --git a/misc-utils/uuidd.8 b/misc-utils/uuidd.8 index ae033eaf..67c6614a 100644 --- a/misc-utils/uuidd.8 +++ b/misc-utils/uuidd.8 @@ -64,11 +64,11 @@ UUID's. .TP .BI \-p " pidfile" Specify the pathname where the pid file should be written. By default, -the pid file is written to /var/lib/libuuid/uuidd.pid. +the pid file is written to /var/run/uuidd/uuidd.pid. .TP .BI \-s " socketpath" Specify the pathname used for the unix-domain socket used by uuidd. By -default, the pathname used is /var/lib/libuuid/request. This is primarily +default, the pathname used is /var/run/uuidd/request. This is primarily for debugging purposes, since the pathname is hard-coded in the libuuid library. .TP diff --git a/shlibs/uuid/src/uuidd.h b/shlibs/uuid/src/uuidd.h index 528acdc9..c8072361 100644 --- a/shlibs/uuid/src/uuidd.h +++ b/shlibs/uuid/src/uuidd.h @@ -35,8 +35,8 @@ #ifndef _UUID_UUIDD_H #define _UUID_UUIDD_H -#define UUIDD_SOCKET_PATH "/var/lib/libuuid/request" -#define UUIDD_PIDFILE_PATH "/var/lib/libuuid/uuidd.pid" +#define UUIDD_SOCKET_PATH "/var/run/uuidd/request" +#define UUIDD_PIDFILE_PATH "/var/run/uuidd/uuidd.pid" #define UUIDD_PATH "/usr/sbin/uuidd" #define UUIDD_OP_GETPID 0 -- cgit v1.2.3 From c74c0daffffbecf1299055fb35908721bcc853b2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Jun 2009 01:13:42 +0200 Subject: include: clean up _PATH_DEV_* macros Signed-off-by: Karel Zak --- include/pathnames.h | 8 +++++++- login-utils/login.c | 4 ++-- misc-utils/script.c | 2 +- mount/lomount.c | 14 ++++++-------- mount/umount.c | 4 +++- tests/expected/paths/built-in | 3 ++- tests/helpers/test_pathnames.c | 3 ++- 7 files changed, 23 insertions(+), 15 deletions(-) (limited to 'misc-utils') 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), -- cgit v1.2.3 From 9a3e4ae5c91abb1f94c691f3a6411e1d9d4acb3b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Jun 2009 15:04:49 +0200 Subject: uuidd: move uuidd.rc to misc-utils directory The file should be on more visible place. Signed-off-by: Karel Zak --- example.files/uuidd.rc | 55 -------------------------------------------------- misc-utils/Makefile.am | 2 +- misc-utils/uuidd.rc | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 56 deletions(-) delete mode 100644 example.files/uuidd.rc create mode 100644 misc-utils/uuidd.rc (limited to 'misc-utils') diff --git a/example.files/uuidd.rc b/example.files/uuidd.rc deleted file mode 100644 index d35645a1..00000000 --- a/example.files/uuidd.rc +++ /dev/null @@ -1,55 +0,0 @@ -#! /bin/sh -e -### BEGIN INIT INFO -# Provides: uuidd -# Required-Start: $time $local_fs -# Required-Stop: $time $local_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: uuidd daemon -# Description: Init script for the uuid generation daemon -### END INIT INFO -# -# Author: "Theodore Ts'o" -# -set -e - -PATH=/bin:/usr/bin:/sbin:/usr/sbin -DAEMON=/usr/sbin/uuidd -PIDFILE=/var/run/uuidd/uuidd.pid - -test -x $DAEMON || exit 0 - -. /lib/lsb/init-functions - -case "$1" in - start) - log_daemon_msg "Starting uuid generator" "uuidd" - start_daemon -p $PIDFILE $DAEMON - log_end_msg $? - ;; - stop) - log_daemon_msg "Stopping uuidd generator" "uuidd" - killproc -p $PIDFILE $DAEMON - log_end_msg $? - ;; - status) - if pidofproc -p $PIDFILE $DAEMON >& /dev/null ; then - echo "$DAEMON is running"; - exit 0; - else - echo "$DAEMON is NOT running"; - if test -f /var/run/uuidd.pid; then exit 2; fi - exit 3; - fi - ;; - force-reload|restart) - $0 stop - $0 start - ;; - *) - echo "Usage: /etc/init.d/uuidd {start|stop|restart|force-reload}" - exit 1 - ;; -esac - -exit 0 diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index 26fa22df..272ef75d 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -1,6 +1,6 @@ include $(top_srcdir)/config/include-Makefile.am -EXTRA_DIST = README.flushb +EXTRA_DIST = README.flushb uuidd.rc bin_PROGRAMS = usrsbinexec_PROGRAMS = diff --git a/misc-utils/uuidd.rc b/misc-utils/uuidd.rc new file mode 100644 index 00000000..d35645a1 --- /dev/null +++ b/misc-utils/uuidd.rc @@ -0,0 +1,55 @@ +#! /bin/sh -e +### BEGIN INIT INFO +# Provides: uuidd +# Required-Start: $time $local_fs +# Required-Stop: $time $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: uuidd daemon +# Description: Init script for the uuid generation daemon +### END INIT INFO +# +# Author: "Theodore Ts'o" +# +set -e + +PATH=/bin:/usr/bin:/sbin:/usr/sbin +DAEMON=/usr/sbin/uuidd +PIDFILE=/var/run/uuidd/uuidd.pid + +test -x $DAEMON || exit 0 + +. /lib/lsb/init-functions + +case "$1" in + start) + log_daemon_msg "Starting uuid generator" "uuidd" + start_daemon -p $PIDFILE $DAEMON + log_end_msg $? + ;; + stop) + log_daemon_msg "Stopping uuidd generator" "uuidd" + killproc -p $PIDFILE $DAEMON + log_end_msg $? + ;; + status) + if pidofproc -p $PIDFILE $DAEMON >& /dev/null ; then + echo "$DAEMON is running"; + exit 0; + else + echo "$DAEMON is NOT running"; + if test -f /var/run/uuidd.pid; then exit 2; fi + exit 3; + fi + ;; + force-reload|restart) + $0 stop + $0 start + ;; + *) + echo "Usage: /etc/init.d/uuidd {start|stop|restart|force-reload}" + exit 1 + ;; +esac + +exit 0 -- cgit v1.2.3 From 4436271060f9e537ce20a9b1dbb57b6ca6e0ce0f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Jun 2009 15:10:20 +0200 Subject: uuidd: fix $PIDFILE in uuidd.rc .. that's very probably a typo. Signed-off-by: Karel Zak --- misc-utils/uuidd.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc-utils') diff --git a/misc-utils/uuidd.rc b/misc-utils/uuidd.rc index d35645a1..e6bc7640 100644 --- a/misc-utils/uuidd.rc +++ b/misc-utils/uuidd.rc @@ -38,7 +38,7 @@ case "$1" in exit 0; else echo "$DAEMON is NOT running"; - if test -f /var/run/uuidd.pid; then exit 2; fi + if test -f $PIDFILE; then exit 2; fdi exit 3; fi ;; -- cgit v1.2.3 From fdb3e93ce907cce3a2133f22bb780ecb317af76a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 30 Jun 2009 22:47:54 -0400 Subject: uuidd: Avoid closing the server socket when calling create_daemon() In the event that file descriptors 0-2 are closed when uuidd is started, the server socket could be created as a file descriptor that will get closed when create_daemon() tries detaching the uuidd daemon from its controlling tty. Avoid this case by using dup(2). Signed-off-by: "Theodore Ts'o" --- misc-utils/uuidd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'misc-utils') diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index 5e597833..42844571 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -274,6 +274,18 @@ static void server_loop(const char *socket_path, const char *pidfile_path, exit(1); } + /* + * Make sure the socket isn't using fd numbers 0-2 to avoid it + * getting closed by create_daemon() + */ + while (!debug && s <= 2) { + s = dup(s); + if (s < 0) { + perror("dup"); + exit(1); + } + } + /* * Create the address we will be binding to. */ -- cgit v1.2.3 From 3b90c50066969cfa40a392d0290cb8d762351f65 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 30 Jun 2009 22:49:49 -0400 Subject: libuuid, uuidd: Avoid infinite loop while reading from the socket fd If for some reason the uuidd daemon or the process calling uuidd exited unexpectely, the read_all() function would end up looping forever, either in uuidd or in libuuid. Fix this terminating the loop if no data can be read after five tries to read from the file descriptor. Signed-off-by: "Theodore Ts'o" --- misc-utils/uuidd.c | 14 +++++++++----- shlibs/uuid/src/gen_uuid.c | 10 +++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'misc-utils') diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index 42844571..74bab693 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -84,19 +84,23 @@ static void create_daemon(void) die("setreuid"); } -static int read_all(int fd, char *buf, size_t count) +static ssize_t read_all(int fd, char *buf, size_t count) { ssize_t ret; - int c = 0; + ssize_t c = 0; + int tries = 0; memset(buf, 0, count); while (count > 0) { ret = read(fd, buf, count); - if (ret < 0) { - if ((errno == EAGAIN) || (errno == EINTR)) + if (ret <= 0) { + if ((errno == EAGAIN || errno == EINTR || ret == 0) && + (tries++ < 5)) continue; - return -1; + return c ? c : -1; } + if (ret > 0) + tries = 0; count -= ret; buf += ret; c += ret; diff --git a/shlibs/uuid/src/gen_uuid.c b/shlibs/uuid/src/gen_uuid.c index 32a6453b..13096c0d 100644 --- a/shlibs/uuid/src/gen_uuid.c +++ b/shlibs/uuid/src/gen_uuid.c @@ -425,15 +425,19 @@ static ssize_t read_all(int fd, char *buf, size_t count) { ssize_t ret; ssize_t c = 0; + int tries = 0; memset(buf, 0, count); while (count > 0) { ret = read(fd, buf, count); - if (ret < 0) { - if ((errno == EAGAIN) || (errno == EINTR)) + if (ret <= 0) { + if ((errno == EAGAIN || errno == EINTR || ret == 0) && + (tries++ < 5)) continue; - return -1; + return c ? c : -1; } + if (ret > 0) + tries = 0; count -= ret; buf += ret; c += ret; -- cgit v1.2.3 From e2d96cd60b139903e546a8af09e7aa5c8db37c35 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 1 Jul 2009 21:25:37 +0200 Subject: uuidd: init /var/run/uuidd, add option for on-demand mode to .rc file Signed-off-by: Karel Zak --- misc-utils/uuidd.rc | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'misc-utils') diff --git a/misc-utils/uuidd.rc b/misc-utils/uuidd.rc index e6bc7640..dbdd5f5c 100644 --- a/misc-utils/uuidd.rc +++ b/misc-utils/uuidd.rc @@ -13,18 +13,34 @@ # set -e +# libuuid is able to execute the uuid daemon on-demand -- in such a case +# the daemon binary must be setuid to an unprivileged user (e.g. uuidd:uuidd). +# [-- kzak Jun 2009] +UUIDD_ON_DEMAND_ONLY="no" + PATH=/bin:/usr/bin:/sbin:/usr/sbin DAEMON=/usr/sbin/uuidd -PIDFILE=/var/run/uuidd/uuidd.pid +UUIDD_USER=uuidd +UUIDD_GROUP=uuidd +UUIDD_DIR=/var/run/uuidd +PIDFILE=$UUIDD_DIR/uuidd.pid test -x $DAEMON || exit 0 . /lib/lsb/init-functions case "$1" in - start) + start) log_daemon_msg "Starting uuid generator" "uuidd" - start_daemon -p $PIDFILE $DAEMON + if ! test -d $UUIDD_DIR; then + mkdir -p $UUIDD_DIR + chown -R $UUIDD_USER:$UUIDD_GROUP $UUIDD_DIR + fi + if test "$UUIDD_ON_DEMAND_ONLY" = yes; then + echo -n "(on demand only)" + else + start_daemon -p $PIDFILE $DAEMON + fi log_end_msg $? ;; stop) @@ -38,10 +54,10 @@ case "$1" in exit 0; else echo "$DAEMON is NOT running"; - if test -f $PIDFILE; then exit 2; fdi + if test -f $PIDFILE; then exit 2; fi exit 3; fi - ;; + ;; force-reload|restart) $0 stop $0 start -- cgit v1.2.3 From 5663298c2c8f3b89be5626ca435b3fd1e5509823 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 2 Jul 2009 14:38:23 +0200 Subject: blkid: move to misc-utils/ directory The others utilities are in one of the top-level directories. That's confusing to have blkid(8) and findfs(8) in shlibs/ tree. Signed-off-by: Karel Zak --- configure.ac | 1 - misc-utils/.gitignore | 2 + misc-utils/Makefile.am | 17 ++ misc-utils/blkid.8 | 211 ++++++++++++++ misc-utils/blkid.c | 633 ++++++++++++++++++++++++++++++++++++++++++ misc-utils/findfs.8 | 35 +++ misc-utils/findfs.c | 60 ++++ shlibs/blkid/Makefile.am | 2 +- shlibs/blkid/bin/Makefile.am | 15 - shlibs/blkid/bin/blkid.8 | 211 -------------- shlibs/blkid/bin/blkid.c | 633 ------------------------------------------ shlibs/blkid/bin/blkid.sh.in | 10 - shlibs/blkid/bin/findfs.8 | 35 --- shlibs/blkid/bin/findfs.c | 60 ---- shlibs/blkid/bin/findfs.sh.in | 10 - tests/commands.sh.in | 2 +- 16 files changed, 960 insertions(+), 977 deletions(-) create mode 100644 misc-utils/blkid.8 create mode 100644 misc-utils/blkid.c create mode 100644 misc-utils/findfs.8 create mode 100644 misc-utils/findfs.c delete mode 100644 shlibs/blkid/bin/Makefile.am delete mode 100644 shlibs/blkid/bin/blkid.8 delete mode 100644 shlibs/blkid/bin/blkid.c delete mode 100644 shlibs/blkid/bin/blkid.sh.in delete mode 100644 shlibs/blkid/bin/findfs.8 delete mode 100644 shlibs/blkid/bin/findfs.c delete mode 100644 shlibs/blkid/bin/findfs.sh.in (limited to 'misc-utils') diff --git a/configure.ac b/configure.ac index 6a870659..96eb68a0 100644 --- a/configure.ac +++ b/configure.ac @@ -911,7 +911,6 @@ mount/Makefile partx/Makefile po/Makefile.in schedutils/Makefile -shlibs/blkid/bin/Makefile shlibs/blkid/blkid.pc shlibs/blkid/Makefile shlibs/blkid/src/Makefile diff --git a/misc-utils/.gitignore b/misc-utils/.gitignore index e58c9301..2242b920 100644 --- a/misc-utils/.gitignore +++ b/misc-utils/.gitignore @@ -14,3 +14,5 @@ kill write uuidgen uuidd +findfs +blkid diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index 272ef75d..7c4561c4 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -3,6 +3,7 @@ include $(top_srcdir)/config/include-Makefile.am EXTRA_DIST = README.flushb uuidd.rc bin_PROGRAMS = +sbin_PROGRAMS = usrsbinexec_PROGRAMS = usrbinexec_PROGRAMS = cal ddate logger look mcookie \ @@ -31,6 +32,22 @@ uuidd_CFLAGS = -I$(ul_libuuid_srcdir) endif endif +if BUILD_LIBBLKID +sbin_PROGRAMS += blkid findfs +dist_man_MANS += blkid.8 findfs.8 +blkid_LDADD = $(ul_libblkid_la) +blkid_CFLAGS = -I$(ul_libblkid_srcdir) +findfs_LDADD = $(ul_libblkid_la) +findfs_CFLAGS = -I$(ul_libblkid_srcdir) +if HAVE_STATIC_BLKID +sbin_PROGRAMS += blkid.static +blkid_static_SOURCES = $(blkid_SOURCES) +blkid_static_LDFLAGS = "-all-static" # libtool option +blkid_static_LDADD = $(ul_libblkid_la) +blkid_static_CFLAGS = -I$(ul_libblkid_srcdir) +endif +endif + if HAVE_TINFO cal_LDADD = -ltinfo @NCURSES_LIBS@ else diff --git a/misc-utils/blkid.8 b/misc-utils/blkid.8 new file mode 100644 index 00000000..ff8e8e57 --- /dev/null +++ b/misc-utils/blkid.8 @@ -0,0 +1,211 @@ +.\" Copyright 2000 Andreas Dilger (adilger@turbolinux.com) +.\" +.\" This man page was created for blkid from e2fsprogs-1.25. +.\" +.\" This file may be copied under the terms of the GNU Public License. +.\" +.\" Based on uuidgen, Mon Sep 17 10:42:12 2000, Andreas Dilger +.TH BLKID 8 "February 2009" "Linux" "MAINTENANCE COMMANDS" +.SH NAME +blkid \- command\-line utility to locate/print block device attributes +.SH SYNOPSIS +.B blkid +.RB \-L +.IR label " | " +.RB \-U +.IR uuid + +.B blkid +.RB [ \-ghlv ] +.RB [ \-c +.IR file ] +.RB [ \-w +.IR file ] +.RB [ \-o +.IR format ] +.in +6 +.RB [ \-s +.IR tag ] +.RB [ \-t +.IR NAME=value ] +.I device +[\fIdevice\fR ...] +.in -6 + +.B blkid +.RB -p +.RB [ \-O +.IR offset ] +.RB [ \-S +.IR size ] +.RB [ \-o +.IR format ] +.RB [ \-u +.IR list ] +.I device +[\fIdevice\fR ...] + +.SH DESCRIPTION +The +.B blkid +program is the command-line interface to working with +.BR libblkid (3) +library. It can determine the type of content (e.g. filesystem, swap) +a block device holds, and also attributes (tokens, NAME=value pairs) +from the content metadata (e.g. LABEL or UUID fields). +.PP +.B blkid +has two main forms of operation: either searching for a device with a +specific NAME=value pair, or displaying NAME=value pairs for one or +more devices. +.SH OPTIONS +.TP +.BI \-c " cachefile" +Read from +.I cachefile +instead of reading from the default cache file +.IR /etc/blkid.tab . +If you want to start with a clean cache (i.e. don't report devices previously +scanned but not necessarily available at this time), specify +.IR /dev/null . +.TP +.B \-g +Perform a garbage collection pass on the blkid cache to remove +devices which no longer exist. +.TP +.B \-h +Display a usage message and exit. +.TP +.B \-l +Look up one device that matches the search parameter specified using +the +.B \-t +option. If there are multiple devices that match the specified search +parameter, then the device with the highest priority is returned, and/or +the first device found at a given priority. Device types in order of +decreasing priority are Device Mapper, EVMS, LVM, MD, and finally regular +block devices. If this option is not specified, +.B blkid +will print all of the devices that match the search parameter. +.TP +.B \-L " label " +Look up one device that uses the label (same as: -l -o device -t +LABEL=