diff options
author | Mihail Konev <k.mvc@ya.ru> | 2016-10-04 17:18:18 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2016-11-20 16:21:49 +0000 |
commit | 9ab9f3dd9b0d5f290c635995559332c1710e5b4d (patch) | |
tree | 5b93577e180228abca5808b2b538d5d35cba5418 | |
parent | 8d82a79d1c7f66cb5d8c104fe5df0de8e58f0e2d (diff) |
man(1): Fix gcc warnings
* lib/xchown.c: New file.
* lib/xchown.h: New file.
* lib/Makefile.am (libman_la_SOURCES): Add xchown.c and xchown.h.
* po/POTFILES.in: Add lib/xchown.c.
* src/check_mandirs.c (mkcatdirs): Call xchown instead of chown.
* src/man.c (format_display): Ignore errors from chdir ("/").
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/Makefile.in | 13 | ||||
-rw-r--r-- | lib/xchown.c | 39 | ||||
-rw-r--r-- | lib/xchown.h | 26 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/check_mandirs.c | 7 | ||||
-rw-r--r-- | src/man.c | 6 |
7 files changed, 88 insertions, 6 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index c3ce5ee2..f4b135db 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -56,6 +56,8 @@ libman_la_SOURCES = \ util.c \ wordfnmatch.c \ wordfnmatch.h \ + xchown.c \ + xchown.h \ xregcomp.c \ xregcomp.h diff --git a/lib/Makefile.in b/lib/Makefile.in index ff8ddc43..4cd5fd19 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -344,7 +344,8 @@ am_libman_la_OBJECTS = libman_la-appendstr.lo libman_la-cleanup.lo \ libman_la-linelength.lo libman_la-lower.lo \ libman_la-orderfiles.lo libman_la-pathsearch.lo \ libman_la-security.lo libman_la-tempfile.lo libman_la-util.lo \ - libman_la-wordfnmatch.lo libman_la-xregcomp.lo + libman_la-wordfnmatch.lo libman_la-xchown.lo \ + libman_la-xregcomp.lo libman_la_OBJECTS = $(am_libman_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -1442,6 +1443,8 @@ libman_la_SOURCES = \ util.c \ wordfnmatch.c \ wordfnmatch.h \ + xchown.c \ + xchown.h \ xregcomp.c \ xregcomp.h @@ -1545,6 +1548,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libman_la-tempfile.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libman_la-util.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libman_la-wordfnmatch.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libman_la-xchown.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libman_la-xregcomp.Plo@am__quote@ .c.o: @@ -1666,6 +1670,13 @@ libman_la-wordfnmatch.lo: wordfnmatch.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libman_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libman_la-wordfnmatch.lo `test -f 'wordfnmatch.c' || echo '$(srcdir)/'`wordfnmatch.c +libman_la-xchown.lo: xchown.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libman_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libman_la-xchown.lo -MD -MP -MF $(DEPDIR)/libman_la-xchown.Tpo -c -o libman_la-xchown.lo `test -f 'xchown.c' || echo '$(srcdir)/'`xchown.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libman_la-xchown.Tpo $(DEPDIR)/libman_la-xchown.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xchown.c' object='libman_la-xchown.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libman_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libman_la-xchown.lo `test -f 'xchown.c' || echo '$(srcdir)/'`xchown.c + libman_la-xregcomp.lo: xregcomp.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libman_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libman_la-xregcomp.lo -MD -MP -MF $(DEPDIR)/libman_la-xregcomp.Tpo -c -o libman_la-xregcomp.lo `test -f 'xregcomp.c' || echo '$(srcdir)/'`xregcomp.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libman_la-xregcomp.Tpo $(DEPDIR)/libman_la-xregcomp.Plo diff --git a/lib/xchown.c b/lib/xchown.c new file mode 100644 index 00000000..760cd748 --- /dev/null +++ b/lib/xchown.c @@ -0,0 +1,39 @@ +/* + * xchown.c: chown replacement function + * + * Copyright (C) 2016 Mihail Konev. + * + * man-db is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * man-db is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with man-db; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <unistd.h> + +#include "gettext.h" +#define _(String) gettext (String) + +#include "error.h" +#include "manconfig.h" + +void xchown (const char *path, uid_t owner, gid_t group) +{ + int rc; + rc = chown (path, owner, group); + if (rc) + error (FATAL, 0, _("can't chown %s"), path); +} diff --git a/lib/xchown.h b/lib/xchown.h new file mode 100644 index 00000000..2193ee80 --- /dev/null +++ b/lib/xchown.h @@ -0,0 +1,26 @@ +/* + * xchown.h: chown replacement function + * + * Copyright (C) 2016 Mihail Konev. + * + * man-db is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * man-db is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with man-db; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * */ + +#ifndef _XCHOWN_H +#define _XCHOWN_H + +void xchown (const char *path, uid_t owner, gid_t group); + +#endif /* _XCHOWN_H */ diff --git a/po/POTFILES.in b/po/POTFILES.in index 0bff2a4a..7fdf9b98 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,5 @@ lib/security.c +lib/xchown.c lib/xregcomp.c libdb/db_delete.c libdb/db_lookup.c diff --git a/src/check_mandirs.c b/src/check_mandirs.c index 496c221c..84e8cf47 100644 --- a/src/check_mandirs.c +++ b/src/check_mandirs.c @@ -56,6 +56,7 @@ #include "hashtable.h" #include "orderfiles.h" #include "security.h" +#include "xchown.h" #include "mydbm.h" #include "db_storage.h" @@ -388,7 +389,7 @@ static void mkcatdirs (const char *mandir, const char *catdir) debug ("created base catdir %s\n", catdir); #ifdef SECURE_MAN_UID if (ruid == 0) - chown (catdir, man_owner->pw_uid, 0); + xchown (catdir, man_owner->pw_uid, 0); #endif /* SECURE_MAN_UID */ drop_effective_privs (); } @@ -413,8 +414,8 @@ static void mkcatdirs (const char *mandir, const char *catdir) debug (" cat%d", j); #ifdef SECURE_MAN_UID if (ruid == 0) - chown (catname, - man_owner->pw_uid, 0); + xchown (catname, + man_owner->pw_uid, 0); #endif /* SECURE_MAN_UID */ } } @@ -1925,7 +1925,8 @@ static void format_display (pipeline *decomp, error (0, errno, _("can't restore previous working " "directory")); - chdir ("/"); + /* last resort */ + if (chdir ("/")) { /* ignore errors */ } } free_cwd (&old_cwd); if (remove_directory (htmldir, 0) == -1) @@ -1961,7 +1962,8 @@ static void format_display (pipeline *decomp, if (have_old_cwd && restore_cwd (&old_cwd) < 0) { error (0, errno, _("can't restore previous working directory")); - chdir ("/"); + /* last resort */ + if (chdir ("/")) { /* ignore errors */ } } free_cwd (&old_cwd); if (remove_directory (htmldir, 0) == -1) |