Subversion Repositories

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

Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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