Removed
Link Here
|
1 |
--- src/process.c.orig 2005-05-08 06:55:00 UTC |
2 |
+++ src/process.c |
3 |
@@ -51,10 +51,19 @@ static char PyFB_setprogname__doc__[] = |
4 |
static PyObject * |
5 |
PyFB_setprogname(PyObject *self, PyObject *args) |
6 |
{ |
7 |
- char *progname; |
8 |
+ const char *progname; |
9 |
+ static PyObject *namestr = NULL; |
10 |
|
11 |
if (!PyArg_ParseTuple(args, "s:setprogname", &progname)) |
12 |
return NULL; |
13 |
+ /* |
14 |
+ * Setprogname(3) does not copy the string, it only stores the |
15 |
+ * string pointer. Make sure that the string object does not |
16 |
+ * get garbage collected and its memory reused! |
17 |
+ */ |
18 |
+ Py_XDECREF(namestr); /* maybe free old progname */ |
19 |
+ PyArg_ParseTuple(args, "O", &namestr); |
20 |
+ Py_INCREF(namestr); /* keep new progname object */ |
21 |
|
22 |
setprogname(progname); |
23 |
Py_RETURN_NONE; |
24 |
@@ -64,16 +73,24 @@ PyFB_setprogname(PyObject *self, PyObjec |
25 |
static char PyFB_setproctitle__doc__[] = |
26 |
"setproctitle(title):\n" |
27 |
"The setproctitle() library routine sets the process title that\n" |
28 |
-"appears on the ps(1) command."; |
29 |
+"appears on the ps(1) command. The progname and a colon are\n" |
30 |
+"prepended automatically. This behaviour is suppressed when the\n" |
31 |
+"title starts with a dash (-) character. Calling with a None\n" |
32 |
+"argument restores a default process title."; |
33 |
|
34 |
static PyObject * |
35 |
PyFB_setproctitle(PyObject *self, PyObject *args) |
36 |
{ |
37 |
- char *newtitle; |
38 |
+ const char *newtitle; |
39 |
|
40 |
- if (!PyArg_ParseTuple(args, "s:setproctitle", &newtitle)) |
41 |
+ if (!PyArg_ParseTuple(args, "z:setproctitle", &newtitle)) |
42 |
return NULL; |
43 |
|
44 |
- setproctitle(newtitle); |
45 |
+ if (newtitle == NULL) |
46 |
+ setproctitle(NULL); |
47 |
+ else if (*newtitle == '-') |
48 |
+ setproctitle("-%s", newtitle+1); |
49 |
+ else |
50 |
+ setproctitle("%s", newtitle); |
51 |
Py_RETURN_NONE; |
52 |
} |