Merge lp:~dannf/ubuntu/saucy/procps/pwdx-fixes into lp:ubuntu/saucy/procps

Proposed by dann frazier on 2013-08-16
Status: Merged
Merge reported by: Adam Conrad
Merged at revision: not available
Proposed branch: lp:~dannf/ubuntu/saucy/procps/pwdx-fixes
Merge into: lp:ubuntu/saucy/procps
Diff against target: 398 lines (+332/-1)
8 files modified
.pc/applied-patches (+2/-0)
.pc/lp1213156-pwdx-pid-0/pwdx.c (+147/-0)
.pc/lp1213160-pwdx-locale-fail/pwdx.c (+147/-0)
debian/changelog (+7/-0)
debian/patches/lp1213156-pwdx-pid-0 (+13/-0)
debian/patches/lp1213160-pwdx-locale-fail (+12/-0)
debian/patches/series (+2/-0)
pwdx.c (+2/-1)
To merge this branch: bzr merge lp:~dannf/ubuntu/saucy/procps/pwdx-fixes
Reviewer Review Type Date Requested Status
Ubuntu branches 2013-08-16 Pending
Review via email: mp+180606@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.pc/applied-patches'
2--- .pc/applied-patches 2012-06-20 13:12:40 +0000
3+++ .pc/applied-patches 2013-08-16 16:17:41 +0000
4@@ -2,3 +2,5 @@
5 bts676239-pkill-u-option
6 watch_8bit
7 uptime_test
8+lp1213156-pwdx-pid-0
9+lp1213160-pwdx-locale-fail
10
11=== added directory '.pc/lp1213156-pwdx-pid-0'
12=== added file '.pc/lp1213156-pwdx-pid-0/.timestamp'
13=== added file '.pc/lp1213156-pwdx-pid-0/pwdx.c'
14--- .pc/lp1213156-pwdx-pid-0/pwdx.c 1970-01-01 00:00:00 +0000
15+++ .pc/lp1213156-pwdx-pid-0/pwdx.c 2013-08-16 16:17:41 +0000
16@@ -0,0 +1,147 @@
17+/*
18+ * pwdx.c - print process working directory
19+ * Copyright 2004 Nicholas Miell
20+ *
21+ * This library is free software; you can redistribute it and/or
22+ * modify it under the terms of the GNU Lesser General Public
23+ * License as published by the Free Software Foundation; either
24+ * version 2.1 of the License, or (at your option) any later version.
25+ *
26+ * This library is distributed in the hope that it will be useful,
27+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
28+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29+ * Lesser General Public License for more details.
30+ *
31+ * You should have received a copy of the GNU Lesser General Public
32+ * License along with this library; if not, write to the Free Software
33+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34+ */
35+
36+#include <errno.h>
37+#include <getopt.h>
38+#include <limits.h>
39+#include <stdio.h>
40+#include <stdlib.h>
41+#include <string.h>
42+#include <sys/types.h>
43+#include <unistd.h>
44+
45+#include "proc/version.h"
46+#include "c.h"
47+#include "nls.h"
48+#include "xalloc.h"
49+#include "fileutils.h"
50+
51+static void __attribute__ ((__noreturn__)) usage(FILE * out)
52+{
53+ fputs(USAGE_HEADER, out);
54+ fprintf(out, _(" %s [options] pid...\n"), program_invocation_short_name);
55+ fputs(USAGE_OPTIONS, out);
56+ fputs(USAGE_HELP, out);
57+ fputs(USAGE_VERSION, out);
58+ fprintf(out, USAGE_MAN_TAIL("pwdx(1)"));
59+
60+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
61+}
62+
63+int check_pid_argument(char *input)
64+{
65+ int skip = 0;
66+ long pid;
67+ char *end = NULL;
68+
69+ if (!strncmp("/proc/", input, 6))
70+ skip = 6;
71+ pid = strtol(input + skip, &end, 10);
72+
73+ if (errno || input + skip == end || (end && *end))
74+ return 1;
75+ if (pid < 1)
76+ return 1;
77+ return 0;
78+}
79+
80+int main(int argc, char *argv[])
81+{
82+ char ch;
83+ int retval = 0, i;
84+ int alloclen = 128;
85+ char *pathbuf;
86+
87+ static const struct option longopts[] = {
88+ {"version", no_argument, 0, 'V'},
89+ {"help", no_argument, 0, 'h'},
90+ {NULL, 0, 0, 0}
91+ };
92+
93+ program_invocation_name = program_invocation_short_name;
94+ setlocale (LC_ALL, "");
95+ bindtextdomain(PACKAGE, LOCALEDIR);
96+ textdomain(PACKAGE);
97+ atexit(close_stdout);
98+
99+ while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
100+ switch (ch) {
101+ case 'V':
102+ printf(PROCPS_NG_VERSION);
103+ return EXIT_SUCCESS;
104+ case 'h':
105+ usage(stdout);
106+ default:
107+ usage(stderr);
108+ }
109+
110+ argc -= optind;
111+ argv += optind;
112+
113+ if (argc == 0)
114+ usage(stderr);
115+
116+ pathbuf = malloc(alloclen);
117+
118+ for (i = 0; i < argc; i++) {
119+ char *s;
120+ ssize_t len, buflen;
121+ /* Constant 10 is the length of strings "/proc/" + "/cwd" + 1 */
122+ char *buf;
123+ buflen = 10 + strlen(argv[i]) + 1;
124+ buf = xmalloc(buflen);
125+
126+ if (check_pid_argument(argv[i]))
127+ xerrx(EXIT_FAILURE, _("invalid process id: %s"),
128+ argv[i]);
129+ /*
130+ * At this point, all arguments are in the form
131+ * /proc/NNNN or NNNN, so a simple check based on
132+ * the first char is possible
133+ */
134+ if (argv[i][0] != '/')
135+ snprintf(buf, buflen, "/proc/%s/cwd", argv[i]);
136+ else
137+ snprintf(buf, buflen, "%s/cwd", argv[i]);
138+
139+ /*
140+ * buf contains /proc/NNNN/cwd symlink name
141+ * on entry, the target of that symlink on return
142+ */
143+ while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
144+ alloclen *= 2;
145+ pathbuf = realloc(pathbuf, alloclen);
146+ }
147+ free(buf);
148+
149+ if (len < 0) {
150+ s = strerror(errno == ENOENT ? ESRCH : errno);
151+ retval = EXIT_FAILURE;
152+ fprintf(stderr, "%s: %s\n", argv[i], s);
153+ continue;
154+ } else {
155+ pathbuf[len] = 0;
156+ s = pathbuf;
157+ }
158+
159+ printf("%s: %s\n", argv[i], s);
160+ }
161+ free(pathbuf);
162+ return retval;
163+}
164
165=== added directory '.pc/lp1213160-pwdx-locale-fail'
166=== added file '.pc/lp1213160-pwdx-locale-fail/.timestamp'
167=== added file '.pc/lp1213160-pwdx-locale-fail/pwdx.c'
168--- .pc/lp1213160-pwdx-locale-fail/pwdx.c 1970-01-01 00:00:00 +0000
169+++ .pc/lp1213160-pwdx-locale-fail/pwdx.c 2013-08-16 16:17:41 +0000
170@@ -0,0 +1,147 @@
171+/*
172+ * pwdx.c - print process working directory
173+ * Copyright 2004 Nicholas Miell
174+ *
175+ * This library is free software; you can redistribute it and/or
176+ * modify it under the terms of the GNU Lesser General Public
177+ * License as published by the Free Software Foundation; either
178+ * version 2.1 of the License, or (at your option) any later version.
179+ *
180+ * This library is distributed in the hope that it will be useful,
181+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
182+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
183+ * Lesser General Public License for more details.
184+ *
185+ * You should have received a copy of the GNU Lesser General Public
186+ * License along with this library; if not, write to the Free Software
187+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
188+ */
189+
190+#include <errno.h>
191+#include <getopt.h>
192+#include <limits.h>
193+#include <stdio.h>
194+#include <stdlib.h>
195+#include <string.h>
196+#include <sys/types.h>
197+#include <unistd.h>
198+
199+#include "proc/version.h"
200+#include "c.h"
201+#include "nls.h"
202+#include "xalloc.h"
203+#include "fileutils.h"
204+
205+static void __attribute__ ((__noreturn__)) usage(FILE * out)
206+{
207+ fputs(USAGE_HEADER, out);
208+ fprintf(out, _(" %s [options] pid...\n"), program_invocation_short_name);
209+ fputs(USAGE_OPTIONS, out);
210+ fputs(USAGE_HELP, out);
211+ fputs(USAGE_VERSION, out);
212+ fprintf(out, USAGE_MAN_TAIL("pwdx(1)"));
213+
214+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
215+}
216+
217+int check_pid_argument(char *input)
218+{
219+ int skip = 0;
220+ long pid;
221+ char *end = NULL;
222+
223+ if (!strncmp("/proc/", input, 6))
224+ skip = 6;
225+ pid = strtol(input + skip, &end, 10);
226+
227+ if (errno || input + skip == end || (end && *end))
228+ return 1;
229+ if (pid < 1)
230+ return 1;
231+ return 0;
232+}
233+
234+int main(int argc, char *argv[])
235+{
236+ int ch;
237+ int retval = 0, i;
238+ int alloclen = 128;
239+ char *pathbuf;
240+
241+ static const struct option longopts[] = {
242+ {"version", no_argument, 0, 'V'},
243+ {"help", no_argument, 0, 'h'},
244+ {NULL, 0, 0, 0}
245+ };
246+
247+ program_invocation_name = program_invocation_short_name;
248+ setlocale (LC_ALL, "");
249+ bindtextdomain(PACKAGE, LOCALEDIR);
250+ textdomain(PACKAGE);
251+ atexit(close_stdout);
252+
253+ while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
254+ switch (ch) {
255+ case 'V':
256+ printf(PROCPS_NG_VERSION);
257+ return EXIT_SUCCESS;
258+ case 'h':
259+ usage(stdout);
260+ default:
261+ usage(stderr);
262+ }
263+
264+ argc -= optind;
265+ argv += optind;
266+
267+ if (argc == 0)
268+ usage(stderr);
269+
270+ pathbuf = malloc(alloclen);
271+
272+ for (i = 0; i < argc; i++) {
273+ char *s;
274+ ssize_t len, buflen;
275+ /* Constant 10 is the length of strings "/proc/" + "/cwd" + 1 */
276+ char *buf;
277+ buflen = 10 + strlen(argv[i]) + 1;
278+ buf = xmalloc(buflen);
279+
280+ if (check_pid_argument(argv[i]))
281+ xerrx(EXIT_FAILURE, _("invalid process id: %s"),
282+ argv[i]);
283+ /*
284+ * At this point, all arguments are in the form
285+ * /proc/NNNN or NNNN, so a simple check based on
286+ * the first char is possible
287+ */
288+ if (argv[i][0] != '/')
289+ snprintf(buf, buflen, "/proc/%s/cwd", argv[i]);
290+ else
291+ snprintf(buf, buflen, "%s/cwd", argv[i]);
292+
293+ /*
294+ * buf contains /proc/NNNN/cwd symlink name
295+ * on entry, the target of that symlink on return
296+ */
297+ while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
298+ alloclen *= 2;
299+ pathbuf = realloc(pathbuf, alloclen);
300+ }
301+ free(buf);
302+
303+ if (len < 0) {
304+ s = strerror(errno == ENOENT ? ESRCH : errno);
305+ retval = EXIT_FAILURE;
306+ fprintf(stderr, "%s: %s\n", argv[i], s);
307+ continue;
308+ } else {
309+ pathbuf[len] = 0;
310+ s = pathbuf;
311+ }
312+
313+ printf("%s: %s\n", argv[i], s);
314+ }
315+ free(pathbuf);
316+ return retval;
317+}
318
319=== modified file 'debian/changelog'
320--- debian/changelog 2013-01-04 17:13:35 +0000
321+++ debian/changelog 2013-08-16 16:17:41 +0000
322@@ -1,3 +1,10 @@
323+procps (1:3.3.3-2ubuntu6) UNRELEASED; urgency=low
324+
325+ * pwdx.c: Fix pwdx argument parsing, fixing FTBFS on arm64 (LP: #1213156)
326+ * pwdx.c: Fix failure when executed in a nonexistent locale (LP: #1213160)
327+
328+ -- dann frazier <dann.frazier@canonical.com> Fri, 16 Aug 2013 10:07:49 -0600
329+
330 procps (1:3.3.3-2ubuntu5) raring; urgency=low
331
332 * Fix cross build.
333
334=== added file 'debian/patches/lp1213156-pwdx-pid-0'
335--- debian/patches/lp1213156-pwdx-pid-0 1970-01-01 00:00:00 +0000
336+++ debian/patches/lp1213156-pwdx-pid-0 2013-08-16 16:17:41 +0000
337@@ -0,0 +1,13 @@
338+Index: procps/pwdx.c
339+===================================================================
340+--- procps.orig/pwdx.c 2013-08-16 09:26:26.606789000 -0600
341++++ procps/pwdx.c 2013-08-16 10:06:49.070216686 -0600
342+@@ -63,7 +63,7 @@
343+
344+ int main(int argc, char *argv[])
345+ {
346+- char ch;
347++ int ch;
348+ int retval = 0, i;
349+ int alloclen = 128;
350+ char *pathbuf;
351
352=== added file 'debian/patches/lp1213160-pwdx-locale-fail'
353--- debian/patches/lp1213160-pwdx-locale-fail 1970-01-01 00:00:00 +0000
354+++ debian/patches/lp1213160-pwdx-locale-fail 2013-08-16 16:17:41 +0000
355@@ -0,0 +1,12 @@
356+Index: procps/pwdx.c
357+===================================================================
358+--- procps.orig/pwdx.c 2013-08-16 10:13:41.723121575 -0600
359++++ procps/pwdx.c 2013-08-16 10:13:47.619192217 -0600
360+@@ -52,6 +52,7 @@
361+
362+ if (!strncmp("/proc/", input, 6))
363+ skip = 6;
364++ errno = 0;
365+ pid = strtol(input + skip, &end, 10);
366+
367+ if (errno || input + skip == end || (end && *end))
368
369=== modified file 'debian/patches/series'
370--- debian/patches/series 2012-06-20 13:12:40 +0000
371+++ debian/patches/series 2013-08-16 16:17:41 +0000
372@@ -2,3 +2,5 @@
373 bts676239-pkill-u-option
374 watch_8bit
375 uptime_test
376+lp1213156-pwdx-pid-0
377+lp1213160-pwdx-locale-fail
378
379=== modified file 'pwdx.c'
380--- pwdx.c 2012-05-20 16:48:44 +0000
381+++ pwdx.c 2013-08-16 16:17:41 +0000
382@@ -52,6 +52,7 @@
383
384 if (!strncmp("/proc/", input, 6))
385 skip = 6;
386+ errno = 0;
387 pid = strtol(input + skip, &end, 10);
388
389 if (errno || input + skip == end || (end && *end))
390@@ -63,7 +64,7 @@
391
392 int main(int argc, char *argv[])
393 {
394- char ch;
395+ int ch;
396 int retval = 0, i;
397 int alloclen = 128;
398 char *pathbuf;

Subscribers

People subscribed via source and target branches

to all changes: