Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 magnus 1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 25_pmksetup.dpatch by Magnus Holmgren <magnus@kibibyte.se>
3
##
4
## DP: Adds -s parameter to pmksetup, which outputs config to standard
5
## DP: output, as well as -g, which forces data gathering to take place
6
## DP: immediately.
7
 
8
@DPATCH@
11 magnus 9
diff -urNad trunk~/pmksetup.c trunk/pmksetup.c
10
--- trunk~/pmksetup.c	2006-10-15 00:31:11.000000000 +0200
11
+++ trunk/pmksetup.c	2007-08-05 15:17:25.000000000 +0200
2 magnus 12
@@ -66,6 +66,7 @@
13
 extern int	 optind;
14
 
15
 FILE		*sfp;			/* scratch file pointer */
16
+bool		 tostdout = false;
17
 char		 sfn[MAXPATHLEN];	/* scratch file name */
18
 
19
 htable		*ht;
20
@@ -154,7 +155,7 @@
21
  ***********************************************************************/
22
 
23
 bool gather_data(htable *pht) {
24
-	printf("==> Looking for default parameters...\n");
25
+	fprintf(stderr, "==> Looking for default parameters...\n");
26
 
27
 	/* gather env variables */
28
 	if (get_env_vars(pht) == false) {
29
@@ -850,7 +851,7 @@
30
 		vsnprintf(buf, sizeof(buf), fmt, plst);
31
 		va_end(plst);
32
 
33
-		printf("%s\n", buf);
34
+		fprintf(stderr, "%s\n", buf);
35
 	}
36
 }
37
 
38
@@ -883,6 +884,13 @@
39
 	optind = 1;
40
 	while ((ch = getopt(argc, argv, PMKSTP_OPT_STR)) != -1) {
41
 		switch(ch) {
42
+			case 'g' :
43
+				if (gather_data(ht) == false)
44
+					return(false);
45
+
46
+				process_clopts = true;
47
+				break;
48
+
49
 			case 'r' :
50
 				/* mark to be deleted in hash */
51
 				if (record_data(ht, optarg, PMKSTP_REC_REMV, NULL) == false) {
52
@@ -932,6 +940,7 @@
53
 				process_clopts = true;
54
 				break;
55
 
56
+			case 's' :
57
 			case 'v' :
58
 			case 'V' :
59
 				/*
60
@@ -949,11 +958,11 @@
61
 	argc -= optind;
62
 	argv += optind;
63
 
64
-	printf("PMKSETUP version %s", PREMAKE_VERSION);
65
+	fprintf(stderr, "PMKSETUP version %s", PREMAKE_VERSION);
66
 #ifdef DEBUG
67
-	printf(" [SUB #%s] [SNAP #%s]", PREMAKE_SUBVER_PMKSETUP, PREMAKE_SNAP);
68
+	fprintf(stderr, " [SUB #%s] [SNAP #%s]", PREMAKE_SUBVER_PMKSETUP, PREMAKE_SNAP);
69
 #endif /* DEBUG */
70
-	printf("\n\n");
71
+	fprintf(stderr, "\n\n");
72
 
73
 	if (process_clopts == false) {
74
 		/* standard behavior, gathering data */
75
@@ -967,7 +976,7 @@
76
 		/* switch backup flag */
77
 		cfg_backup = true;
78
 
79
-		printf("==> Configuration file found: %s\n",
80
+		fprintf(stderr, "==> Configuration file found: %s\n",
81
 						PREMAKE_CONFIG_PATH);
82
 		if (parse_pmkconf(config, ht, PRS_PMKCONF_SEP,
83
 						check_opt) == false) {
84
@@ -978,10 +987,10 @@
85
 			fclose(config);
86
 		}
87
 	} else {
88
-		printf("==> Configuration file not found.\n");
89
+		fprintf(stderr, "==> Configuration file not found.\n");
90
 	}
91
 
92
-	printf("==> Merging remaining data...\n");
93
+	fprintf(stderr, "==> Merging remaining data...\n");
94
 	/* writing the remaining data stored in the hash */
95
 	if (write_new_data(ht) == false)
96
 		return(false);
97
@@ -1099,6 +1108,9 @@
98
 	/* if child status is ok, writing changes */
99
 	if (status == 0) {
100
 #endif
101
+		if (tostdout) {
102
+			return;
103
+	  	}
104
 		/*
105
 		 * check if pmk.conf already exists
106
 		 * NOTE: no race condition here for access(), BUT
107
@@ -1106,7 +1118,7 @@
108
 		 */
109
 		if (access(PREMAKE_CONFIG_PATH, F_OK) == 0) { /* see above */
110
 			/* backup configuration file */
111
-			printf("==> Backing up configuration file: %s\n",
112
+			fprintf(stderr, "==> Backing up configuration file: %s\n",
113
 						PREMAKE_CONFIG_PATH_BAK);
114
 
115
 			if (rename(PREMAKE_CONFIG_PATH,
116
@@ -1118,7 +1130,7 @@
117
 		}
118
 
119
 		/* copying the temporary config to the system one */
120
-		printf("==> Saving configuration file: %s\n",
121
+		fprintf(stderr, "==> Saving configuration file: %s\n",
122
 						PREMAKE_CONFIG_PATH);
123
 		if (fcopy(sfn, PREMAKE_CONFIG_PATH,
124
 					PREMAKE_CONFIG_MODE) == false) {
11 magnus 125
@@ -1129,15 +1141,17 @@
126
 	}
127
 #endif
128
 
129
+	if (!tostdout) {
130
 #ifdef PMKSETUP_DEBUG
131
-	debugf("%s has not been deleted!", sfn);
132
+		debugf("%s has not been deleted!", sfn);
133
 #else
134
-	if (unlink(sfn) == -1) {
135
-		errorf("cannot remove temporary file: '%s' : %s.",
136
-					sfn, strerror(errno));
137
-		error = true;
138
-	}
139
+		if (unlink(sfn) == -1) {
140
+			errorf("cannot remove temporary file: '%s' : %s.",
141
+						sfn, strerror(errno));
142
+			error = true;
143
+		}
144
 #endif	/* PMKSETUP_DEBUG */
145
+	}
146
 
147
 #ifndef WITHOUT_FORK
148
 	if (status != 0) {
149
@@ -1165,7 +1179,7 @@
2 magnus 150
  ***********************************************************************/
151
 
152
 void usage(void) {
153
-	fprintf(stderr, "usage: pmksetup [-hVv] "
154
+	fprintf(stderr, "usage: pmksetup [-hsVv] "
155
 		"[-r variable] [-u variable=value]\n");
156
 	exit(EXIT_FAILURE);
157
 }
11 magnus 158
@@ -1188,6 +1202,7 @@
2 magnus 159
 	optind = 1;
160
 	while ((ch = getopt(argc, argv, PMKSTP_OPT_STR)) != -1) {
161
 		switch(ch) {
162
+			case 'g' :
163
 			case 'r' :
164
 			case 'u' :
165
 				/*
11 magnus 166
@@ -1206,6 +1221,10 @@
2 magnus 167
 					verbose_flag = 1;
168
 				break;
169
 
170
+			case 's':
171
+				tostdout = true;
172
+				break;
173
+
174
 			case '?' :
175
 			default :
176
 				usage();
11 magnus 177
@@ -1213,7 +1232,6 @@
2 magnus 178
 		}
179
 	}
180
 
181
-
182
 	if (getuid() == 0) {
183
 #ifdef PMKSETUP_DEBUG
184
 		debugf("PRIVSEP_USER = '%s'", PRIVSEP_USER);
11 magnus 185
@@ -1227,22 +1245,27 @@
2 magnus 186
 		gid = pw->pw_gid;
187
 	}
188
 
189
-	/* check if syconfdir exists */
190
-	if (access(CONFDIR, F_OK) != 0) { /* no race condition, just mkdir() */
191
-		verbosef("==> Creating '%s' directory.", CONFDIR);
192
-		if (mkdir(CONFDIR, S_IRWXU | S_IRGRP | S_IXGRP |
193
-						S_IROTH | S_IXOTH) != 0) {
194
-			errorf("cannot create '%s' directory : %s.",
195
-						CONFDIR, strerror(errno));
196
-			exit(EXIT_FAILURE);
197
-		}
198
+	if (tostdout) {
199
+		sfp = stdout;
200
 	}
201
+	else {
202
+		/* check if syconfdir exists */
203
+		if (access(CONFDIR, F_OK) != 0) { /* no race condition, just mkdir() */
204
+			verbosef("==> Creating '%s' directory.", CONFDIR);
205
+			if (mkdir(CONFDIR, S_IRWXU | S_IRGRP | S_IXGRP |
206
+							   S_IROTH | S_IXOTH) != 0) {
207
+				errorf("cannot create '%s' directory : %s.",
208
+							CONFDIR, strerror(errno));
209
+				exit(EXIT_FAILURE);
210
+			}
211
+		}
212
 
213
-	sfp = tmp_open(PREMAKE_CONFIG_TMP, "w", sfn, sizeof(sfn));
214
-	if (sfp == NULL) {
215
-		errorf("cannot open temporary file '%s' : %s.",
216
-				sfn, strerror(errno));
217
-		exit(EXIT_FAILURE);
218
+		sfp = tmp_open(PREMAKE_CONFIG_TMP, "w", sfn, sizeof(sfn));
219
+		if (sfp == NULL) {
220
+			errorf("cannot open temporary file '%s' : %s.",
221
+					sfn, strerror(errno));
222
+			exit(EXIT_FAILURE);
223
+		}
224
 	}
225
 
226
 #ifndef WITHOUT_FORK
11 magnus 227
diff -urNad trunk~/pmksetup.h trunk/pmksetup.h
228
--- trunk~/pmksetup.h	2005-05-14 13:37:38.000000000 +0200
229
+++ trunk/pmksetup.h	2007-08-05 15:09:51.000000000 +0200
230
@@ -85,7 +85,7 @@
231
 #define	ECHO_NL		"\\n"
232
 #define	ECHO_HT		"\\t"
233
 
234
-#define PMKSTP_OPT_STR	"hr:u:vV"	/* "a:hr:u:vV" */
235
+#define PMKSTP_OPT_STR	"ghr:su:vV"	/* "a:hr:u:vV" */
236
 
237
 #define EMSG_PRIV_FMT	"Failed to change privilege (%s)"
238