Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 192682 | Differences between
and this patch

Collapse All | Expand All

(-)baselayout-2.0.0_rc4/src/builtins.h (+1 lines)
Lines 15-18 Link Here
15
int rc_update (int argc, char **argv);
15
int rc_update (int argc, char **argv);
16
int runscript (int argc, char **argv);
16
int runscript (int argc, char **argv);
17
int start_stop_daemon (int argc, char **argv);
17
int start_stop_daemon (int argc, char **argv);
18
int checkdir (int argc, char **argv);
18
19
(-)baselayout-2.0.0_rc4/src/checkdir.c (+122 lines)
Line 0 Link Here
1
/*
2
   checkdir.c
3
   Checks for the existance of a directory and creates it
4
   if necessary. It can also correct its ownership.
5
6
   Copyright 2007 Gentoo Foundation
7
   */
8
9
#define APPLET "checkdir"
10
11
#include <errno.h>
12
#include <getopt.h>
13
#include <stdio.h>
14
#include <stdlib.h>
15
#include <string.h>
16
#include <unistd.h>
17
#include <sys/stat.h>
18
#include <sys/types.h>
19
#include <pwd.h>
20
#include <grp.h>
21
22
#include "builtins.h"
23
#include "einfo.h"
24
25
#include "_usage.h"
26
#define getoptstring "d:o:" getoptstring_COMMON
27
static struct option longopts[] = {
28
	{ "directory",      1, NULL, 'd'},
29
	{ "chown",          1, NULL, 'o'},
30
	longopts_COMMON
31
	{ NULL,             0, NULL, 0}
32
};
33
#include "_usage.c"
34
35
int checkdir (int argc, char **argv)
36
{
37
	int opt;
38
	char *path = NULL;
39
	struct stat dirstat;
40
41
	char *owner = NULL;
42
	char *group = NULL;
43
44
	uid_t uid = getuid();
45
	gid_t gid = getgid();
46
47
	while ((opt = getopt_long (argc, argv, getoptstring,
48
		longopts, (int *) 0)) != -1)
49
	{
50
		switch (opt) {
51
			case 'd':
52
				path = optarg;
53
				break;
54
55
			case 'o':
56
				owner = strsep (&optarg, ":");
57
				if (owner[0] == '\0')
58
				{
59
					owner = NULL;
60
				}
61
				group = optarg;
62
				break;
63
64
			case_RC_COMMON_GETOPT
65
		}
66
67
	}
68
69
	if (path == NULL)
70
	{
71
		exit(EXIT_FAILURE);
72
	}	
73
74
	/* create dir, if it doesn't exist */
75
	if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
76
	{
77
		if (errno != EEXIST)
78
		{
79
			eerrorx("%s: mkdir: %s", argv[0], strerror(errno));
80
		}
81
	}
82
	else
83
	{
84
		einfo("Created directory %s", path);
85
	}
86
87
	if (stat(path, &dirstat))
88
	{
89
		eerrorx("%s: %s", argv[0], strerror(errno));
90
	}
91
92
	if (owner != NULL)
93
	{
94
		struct passwd *pwd;
95
		if ( (pwd = getpwnam(owner)) == NULL)
96
		{
97
			eerrorx("%s: Can't set owner: %s", argv[0], owner);
98
		}
99
		uid = pwd->pw_uid;
100
	}
101
102
	if (group != NULL)
103
	{
104
		struct group *grp;
105
		if ( (grp = getgrnam(group)) == NULL)
106
		{
107
			eerrorx("%s: Can't set group: %s", argv[0], group);
108
		}
109
		gid = grp->gr_gid;
110
	}
111
112
	if (dirstat.st_uid != uid || dirstat.st_gid != gid)
113
	{
114
		einfo("Correcting directory ownership.");
115
		if (chown(path, uid, gid))
116
		{
117
			eerrorx("%s: chown: %s", argv[0], strerror(errno));
118
		}
119
	}
120
121
	exit(EXIT_SUCCESS);
122
}
(-)baselayout-2.0.0_rc4/src/Makefile (-1 / +1 lines)
Lines 34-40 Link Here
34
34
35
RCOBJS = env-update.o fstabinfo.o mountinfo.o \
35
RCOBJS = env-update.o fstabinfo.o mountinfo.o \
36
		 rc-depend.o rc-plugin.o rc-status.o rc-update.o runscript.o \
36
		 rc-depend.o rc-plugin.o rc-status.o rc-update.o runscript.o \
37
		 start-stop-daemon.o
37
		 start-stop-daemon.o checkdir.o
38
38
39
LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO)
39
LIB_TARGETS = $(LIBEINFOSO) $(LIBRCSO)
40
SBIN_TARGETS = rc
40
SBIN_TARGETS = rc
(-)baselayout-2.0.0_rc4/src/rc.c (+2 lines)
Lines 758-763 Link Here
758
		exit (runscript (argc, argv));
758
		exit (runscript (argc, argv));
759
	else if (strcmp (applet, "start-stop-daemon") == 0)
759
	else if (strcmp (applet, "start-stop-daemon") == 0)
760
		exit (start_stop_daemon (argc, argv));
760
		exit (start_stop_daemon (argc, argv));
761
	else if (strcmp (applet, "checkdir") == 0)
762
		exit (checkdir (argc, argv));
761
763
762
	argc--;
764
	argc--;
763
	argv++;
765
	argv++;

Return to bug 192682