From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steven Whitehouse Date: Wed, 07 May 2014 15:39:06 +0100 Subject: [Cluster-devel] [PATCH 1/5] fsck.gfs2: Log to syslog on start and exit In-Reply-To: <1399473221-28521-1-git-send-email-anprice@redhat.com> References: <1399473221-28521-1-git-send-email-anprice@redhat.com> Message-ID: <536A458A.2080507@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, On 07/05/14 15:33, Andrew Price wrote: > In order to piece together the order in which fsck.gfs2 runs and > gfs2_edit savemeta were done it's useful to keep a log of the command > line options used and the fsck.gfs2 start and end times. Log these to > syslog. > > Signed-off-by: Andrew Price > --- > gfs2/fsck/main.c | 35 +++++++++++++++++++++++++++++++++++ > gfs2/man/fsck.gfs2.8 | 2 ++ > 2 files changed, 37 insertions(+) > > diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c > index 346e580..0031ec0 100644 > --- a/gfs2/fsck/main.c > +++ b/gfs2/fsck/main.c > @@ -12,6 +12,7 @@ > #include > #include > #define _(String) gettext(String) > +#include > > #include "copyright.cf" > #include "libgfs2.h" > @@ -261,6 +262,36 @@ static int fsck_pass(const struct fsck_pass *p, struct gfs2_sbd *sdp) > return 0; > } > > +static void exitlog(void) > +{ > + syslog(LOG_INFO, "exiting."); > +} > + Would be nice if it was possible to log the exit status too here... > +static void startlog(int argc, char **argv) > +{ > + int i; > + char *cmd, *p; > + size_t len; > + > + for (len = i = 0; i < argc; i++) > + len += strlen(argv[i]); > + len += argc; /* Add spaces and '\0' */ > + > + cmd = malloc(len); > + if (cmd == NULL) { > + perror(argv[0]); > + exit(FSCK_ERROR); > + } > + p = cmd; > + for (i = 0; i < argc; i++, p++) { > + p = stpcpy(p, argv[i]); > + *p = ' '; > + } > + *(--p) = '\0'; > + syslog(LOG_INFO, "started: %s", cmd); If you use vsyslog rather than syslog I wonder if its possible to make this a bit neater? Steve. > + free(cmd); > +} > + > int main(int argc, char **argv) > { > struct gfs2_sbd sb; > @@ -274,6 +305,10 @@ int main(int argc, char **argv) > setlocale(LC_ALL, ""); > textdomain("gfs2-utils"); > > + openlog("fsck.gfs2", LOG_CONS|LOG_PID, LOG_USER); > + startlog(argc - 1, &argv[1]); > + atexit(exitlog); > + > memset(sdp, 0, sizeof(*sdp)); > > if ((error = read_cmdline(argc, argv, &opts))) > diff --git a/gfs2/man/fsck.gfs2.8 b/gfs2/man/fsck.gfs2.8 > index 3ecfbe3..56dcddc 100644 > --- a/gfs2/man/fsck.gfs2.8 > +++ b/gfs2/man/fsck.gfs2.8 > @@ -35,6 +35,8 @@ computer. Therefore, fsck.gfs2 will always check the file system unless > the -p (preen) option is used, in which case it follows special rules > (see below). > > +fsck.gfs2 will log to the system log on start and exit to aid debugging and > +administration. > .SH OPTIONS > .TP > \fB-a\fP