ttrace: enhance -ttrace_vblank option
[platform/core/uifw/libtdm.git] / src / tdm_monitor_server.c
1 /**************************************************************************
2  *
3  * libtdm
4  *
5  * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6  *
7  * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8  *          JinYoung Jeon <jy0.jeon@samsung.com>,
9  *          Taeheon Kim <th908.kim@samsung.com>,
10  *          YoungJun Cho <yj44.cho@samsung.com>,
11  *          SooChan Lim <sc1.lim@samsung.com>,
12  *          Boram Park <sc1.lim@samsung.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the
16  * "Software"), to deal in the Software without restriction, including
17  * without limitation the rights to use, copy, modify, merge, publish,
18  * distribute, sub license, and/or sell copies of the Software, and to
19  * permit persons to whom the Software is furnished to do so, subject to
20  * the following conditions:
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34 **************************************************************************/
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <stdint.h>
40
41 #include "tdm.h"
42 #include "tdm_private.h"
43 #include "tdm_helper.h"
44 #include "tdm_log.h"
45
46 #define TDM_DBG_SERVER_ARGS_MAX         32
47
48 static void _tdm_monitor_server_usage(char *app_name, char *reply, int *len);
49
50 static void
51 _tdm_monitor_server_query(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
52 {
53         tdm_display_lock(dpy);
54         tdm_helper_get_display_information(dpy, reply, len);
55         tdm_display_unlock(dpy);
56 }
57
58 static void
59 _tdm_monitor_server_protocol_trace(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
60 {
61         int enable;
62
63         if (argc < 3) {
64                 _tdm_monitor_server_usage(argv[0], reply, len);
65                 return;
66         }
67
68         enable = atoi(argv[2]);
69
70         tdm_event_loop_trace_enable(dpy, enable);
71
72         TDM_SNPRINTF(reply, len, "protocol trace: '%s'\n", (enable) ? "enabled" : "disabled");
73 }
74
75 static void
76 _tdm_monitor_server_dpms(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
77 {
78         tdm_output *output;
79         int output_idx, dpms_value;
80         char *arg;
81         char *end;
82         tdm_error ret;
83
84         if (argc < 3) {
85                 _tdm_monitor_server_usage(argv[0], reply, len);
86                 return;
87         }
88
89         arg = argv[2];
90         output_idx = strtol(arg, &end, 10);
91         if (*end != ':') {
92                 TDM_SNPRINTF(reply, len, "failed: no onoff value\n");
93                 return;
94         }
95
96         arg = end + 1;
97         dpms_value = strtol(arg, &end, 10);
98
99         output = tdm_display_get_output(dpy, output_idx, &ret);
100         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
101
102         ret = tdm_output_set_dpms(output, dpms_value);
103         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
104
105         TDM_SNPRINTF(reply, len, "done: DPMS %s\n", tdm_dpms_str(dpms_value));
106 }
107
108 static void
109 _tdm_monitor_server_ttrace_vblank(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
110 {
111         int ttrace_vblank, output_id = 0;
112         char *arg;
113         char *end;
114
115         if (argc < 3) {
116                 _tdm_monitor_server_usage(argv[0], reply, len);
117                 return;
118         }
119
120         arg = argv[2];
121         ttrace_vblank = strtol(arg, &end, 10);
122
123         if (ttrace_vblank > 0) {
124                 tdm_output *output;
125                 tdm_error ret;
126                 tdm_output_type type;
127                 char *temp;
128
129                 if (*end == '@') {
130                         arg = end + 1;
131                         output_id = strtol(arg, &end, 10);
132                 }
133
134                 output = tdm_display_get_output(dpy, output_id, NULL);
135                 if (!output) {
136                         TDM_SNPRINTF(reply, len, "can't find the output_id(%d)\n", output_id);
137                         return;
138                 }
139
140                 ret = tdm_output_get_output_type(output, &type);
141                 if (ret != TDM_ERROR_NONE) {
142                         TDM_SNPRINTF(reply, len, "can't find the type of output_id(%d)\n", output_id);
143                         return;
144                 }
145
146                 temp = "server";
147                 tdm_display_enable_ttrace_vblank(dpy, output, 1);
148
149                 if (ttrace_vblank > 1) {
150                         temp = "clients";
151                         tdm_server_enable_ttrace_vblank(dpy, output, 1);
152                 }
153
154                 TDM_SNPRINTF(reply, len, "enable ttrace vblank for '%s': %s \n", tdm_conn_str(type), temp);
155         } else {
156                 tdm_display_enable_ttrace_vblank(dpy, NULL, 0);
157                 tdm_server_enable_ttrace_vblank(dpy, NULL, 0);
158                 TDM_SNPRINTF(reply, len, "disable ttrace vblank\n");
159         }
160 }
161
162 static void
163 _tdm_monitor_server_debug(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
164 {
165         int level;
166         char *arg;
167         char *end;
168
169         if (argc < 3) {
170                 _tdm_monitor_server_usage(argv[0], reply, len);
171                 return;
172         }
173
174         arg = argv[2];
175         level = strtol(arg, &end, 10);
176
177         tdm_log_set_debug_level(level);
178         TDM_SNPRINTF(reply, len, "debug level: %d\n", level);
179
180         if (*end == '@') {
181                 char *arg = end + 1;
182
183                 tdm_display_enable_debug_module((const char *)arg);
184
185                 TDM_SNPRINTF(reply, len, "debugging... '%s'\n", arg);
186         }
187 }
188
189 static void
190 _tdm_monitor_server_log_path(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
191 {
192         static int old_stdout = -1;
193         char fd_name[TDM_PATH_LEN];
194         char *path;
195
196         if (argc < 3) {
197                 _tdm_monitor_server_usage(argv[0], reply, len);
198                 return;
199         }
200
201         if (old_stdout == -1)
202                 old_stdout = dup(STDOUT_FILENO);
203
204         path = argv[2];
205         TDM_DBG_RETURN_IF_FAIL(path != NULL);
206
207         tdm_log_enable_dlog(0);
208
209         if (!strncmp(path, "dlog", 4)) {
210                 tdm_log_enable_dlog(1);
211                 goto done;
212         } else if (!strncmp(path, "console", 7))
213                 snprintf(fd_name, TDM_PATH_LEN, "/proc/%d/fd/1", pid);
214         else {
215                 if (path[0] == '/')
216                         snprintf(fd_name, TDM_PATH_LEN, "%s", path);
217                 else {
218                         if (cwd)
219                                 snprintf(fd_name, TDM_PATH_LEN, "%s/%s", cwd, path);
220                         else
221                                 snprintf(fd_name, TDM_PATH_LEN, "%s", path);
222                 }
223                 tdm_log_enable_color(0);
224         }
225
226         if (tdm_display_enable_path((const char*)fd_name) != TDM_ERROR_NONE) {
227                 TDM_SNPRINTF(reply, len, "failed: '%s'\n", path);
228                 return;
229         }
230
231 done:
232         TDM_SNPRINTF(reply, len, "log path: '%s'\n", path);
233 }
234
235 static void
236 _tdm_monitor_server_choose_commit_per_vblank_mode(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
237 {
238         int output_idx;
239         int mode;
240         char *arg;
241         char *end;
242         tdm_error err;
243
244         /* TODO: do we have to provide an ability to choose commit_per_vblank mode outside? */
245
246         if (argc < 4) {
247                 _tdm_monitor_server_usage(argv[0], reply, len);
248                 return;
249         }
250
251         arg = argv[2];
252         output_idx = strtol(arg, &end, 10);
253
254         arg = argv[3];
255         mode = strtol(arg, &end, 10);
256
257         err = tdm_output_choose_commit_per_vblank_mode(tdm_display_get_output(dpy, output_idx, NULL), mode);
258         if (err != TDM_ERROR_NONE) {
259                 TDM_SNPRINTF(reply, len, "an error: output_idx or mode is wrong\n");
260                 return;
261         }
262
263         TDM_SNPRINTF(reply, len, "the mode's been set\n");
264 }
265
266 static void
267 _tdm_monitor_server_fps(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
268 {
269         int enable;
270         char *arg;
271         char *end;
272
273         if (argc < 3) {
274                 _tdm_monitor_server_usage(argv[0], reply, len);
275                 return;
276         }
277
278         arg = argv[2];
279         enable = strtol(arg, &end, 10);
280
281         tdm_display_enable_fps(dpy, enable);
282
283         TDM_SNPRINTF(reply, len, "%s to print fps\n", (enable) ? "enable" : "disable");
284 }
285
286 static void
287 _tdm_monitor_server_vblank_list(unsigned int pid, char *cwd, int argc, char *argv[],
288                                                                 char *reply, int *len, tdm_display *dpy)
289 {
290         tdm_vblank_get_vblank_list_information(dpy, reply, len);
291 }
292
293 static void
294 _tdm_monitor_server_vblank_fps(unsigned int pid, char *cwd, int argc, char *argv[],
295                                                            char *reply, int *len, tdm_display *dpy)
296 {
297         unsigned int target_pid, fps;
298         char *arg;
299         char *end;
300         char name[TDM_NAME_LEN];
301         tdm_error ret;
302
303         if (argc < 3) {
304                 _tdm_monitor_server_usage(argv[0], reply, len);
305                 return;
306         }
307
308         arg = argv[2];
309         target_pid = strtol(arg, &end, 10);
310
311         if (*end == ',') {
312                 arg = end + 1;
313                 end = strtostr(name, TDM_NAME_LEN, arg, TDM_DELIM);
314         } else {
315                 strncpy(name, TDM_VBLANK_DEFAULT_NAME, TDM_NAME_LEN - 1);
316                 name[TDM_NAME_LEN - 1] = '\0';
317         }
318
319         if (*end != '@') {
320                 TDM_SNPRINTF(reply, len, "failed: no fps value\n");
321                 return;
322         }
323
324         arg = end + 1;
325         fps = strtol(arg, &end, 10);
326
327         ret = tdm_vblank_set_client_vblank_fps(target_pid, name, fps);
328         if (ret != TDM_ERROR_NONE) {
329                 TDM_SNPRINTF(reply, len, "can't set '%u' fps to '%s' client vblank(PID:%u)\n", fps, name, target_pid);
330                 return;
331         }
332
333         TDM_SNPRINTF(reply, len, "success: '%u' fps for '%s' client vblank(PID:%u)\n", fps, name, target_pid);
334 }
335
336 static void
337 _tdm_monitor_server_global_fps(unsigned int pid, char *cwd, int argc, char *argv[],
338                                                            char *reply, int *len, tdm_display *dpy)
339 {
340         unsigned int fps;
341         char *arg;
342         char *end;
343         tdm_error ret;
344
345         if (argc < 3) {
346                 _tdm_monitor_server_usage(argv[0], reply, len);
347                 return;
348         }
349
350         arg = argv[2];
351         fps = strtol(arg, &end, 10);
352
353         if (fps > 0)
354                 ret = tdm_vblank_enable_global_fps(1, fps);
355         else
356                 ret = tdm_vblank_enable_global_fps(0, 0);
357
358         if (ret != TDM_ERROR_NONE) {
359                 TDM_SNPRINTF(reply, len, "can't set '%u' fps to global fps\n", fps);
360                 return;
361         }
362
363         TDM_SNPRINTF(reply, len, "success: '%u' global fps\n", fps);
364 }
365
366 static void
367 _tdm_monitor_server_prop(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
368 {
369         tdm_output *output;
370         tdm_output *layer = NULL;
371         int output_idx, layer_idx = -1;
372         int cnt, i, done = 0;
373         tdm_value value;
374         char temp[TDM_PATH_LEN];
375         char *prop_name;
376         char *arg;
377         char *end;
378         tdm_error ret;
379         const tdm_prop *props;
380
381         if (argc < 3) {
382                 _tdm_monitor_server_usage(argv[0], reply, len);
383                 return;
384         }
385
386         snprintf(temp, TDM_PATH_LEN, "%s", argv[2]);
387         arg = temp;
388
389         output_idx = strtol(arg, &end, 10);
390         if (*end == ',') {
391                 arg = end + 1;
392                 layer_idx = strtol(arg, &end, 10);
393         }
394
395         if (*end != ':') {
396                 TDM_SNPRINTF(reply, len, "failed: no prop_name\n");
397                 return;
398         }
399
400         arg = end + 1;
401         prop_name = strtok_r(arg, ",", &end);
402         if (!prop_name) {
403                 TDM_SNPRINTF(reply, len, "failed: get prop_name by strtok_r\n");
404                 return;
405         }
406
407         if (*end == '\0') {
408                 TDM_SNPRINTF(reply, len, "failed: no value\n");
409                 return;
410         }
411
412         arg = strtok_r(NULL, TDM_DELIM, &end);
413         if (!arg) {
414                 TDM_SNPRINTF(reply, len, "failed: get arg by strtok_r\n");
415                 return;
416         }
417         value.u32 = strtol(arg, &end, 10);
418
419         output = tdm_display_get_output(dpy, output_idx, &ret);
420         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && output != NULL);
421
422         if (layer_idx != -1) {
423                 layer = tdm_output_get_layer(output, layer_idx, &ret);
424                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE && layer != NULL);
425         }
426
427         if (layer) {
428                 ret = tdm_layer_get_available_properties(layer, &props, &cnt);
429                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
430
431                 for (i = 0; i < cnt; i++) {
432                         if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
433                                 ret = tdm_layer_set_property(layer, props[i].id, value);
434                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
435                                 done = 1;
436                                 break;
437                         }
438                 }
439         } else {
440                 ret = tdm_output_get_available_properties(output, &props, &cnt);
441                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
442
443                 for (i = 0; i < cnt; i++) {
444                         if (!strncmp(props[i].name, prop_name, TDM_NAME_LEN)) {
445                                 ret = tdm_output_set_property(output, props[i].id, value);
446                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
447                                 done = 1;
448                                 break;
449                         }
450                 }
451         }
452
453         if (done)
454                 TDM_SNPRINTF(reply, len, "done: %s:%d \n", prop_name, value.u32);
455         else
456                 TDM_SNPRINTF(reply, len, "no '%s' propperty \n", prop_name);
457 }
458
459 static void
460 _tdm_monitor_server_dump(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
461 {
462         if (argc < 3) {
463                 _tdm_monitor_server_usage(argv[0], reply, len);
464                 return;
465         }
466
467         tdm_display_enable_dump(dpy, (const char*)argv[2], reply, len);
468 }
469
470 static void
471 _tdm_monitor_server_punch(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy)
472 {
473         char *arg, *end;
474         unsigned int output_id, layer_id;
475         tdm_output *output;
476         tdm_layer *layer;
477         tbm_surface_h buffer;
478
479         arg = argv[2];
480
481         output_id = strtol(arg, &end, 10);
482         output = tdm_display_get_output(dpy, output_id, NULL);
483         if (!output) {
484                 TDM_SNPRINTF(reply, len, "not found output\n");
485                 return;
486         }
487         if (*end != ',') {
488                 TDM_SNPRINTF(reply, len, "not found ',<layer_idx>'\n");
489                 return;
490         }
491
492         arg = end + 1;
493         layer_id = strtol(arg, &end, 10);
494         layer = tdm_output_get_layer(output, layer_id, NULL);
495         if (!layer) {
496                 TDM_SNPRINTF(reply, len, "not found layer\n");
497                 return;
498         }
499
500         buffer = tdm_layer_get_displaying_buffer(layer, NULL);
501         if (!buffer) {
502                 TDM_SNPRINTF(reply, len, "not found buffer\n");
503                 return;
504         }
505
506         if (*end == ':') {
507                 tdm_pos pos = {0,};
508
509                 arg = end + 1;
510                 pos.w = strtol(arg, &end, 10);
511                 TDM_EXIT_IF_FAIL(*end == 'x');
512                 arg = end + 1;
513                 pos.h = strtol(arg, &end, 10);
514                 if (*end == '+') {
515                         arg = end + 1;
516                         pos.x = strtol(arg, &end, 10);
517                         TDM_EXIT_IF_FAIL(*end == '+');
518                         arg = end + 1;
519                         pos.y = strtol(arg, &end, 10);
520                 }
521
522                 tdm_helper_clear_buffer_pos(buffer, &pos);
523         } else
524                 tdm_helper_clear_buffer(buffer);
525 }
526
527 static struct {
528         const char *opt;
529         void (*func)(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy);
530         const char *desc;
531         const char *arg;
532         const char *ex;
533 } option_proc[] = {
534         {
535                 "info", _tdm_monitor_server_query,
536                 "show tdm output, layer information", NULL, NULL
537         },
538         {
539                 "trace", _tdm_monitor_server_protocol_trace,
540                 "enable/disable the wl protocol",
541                 "<enable>",
542                 "0 or 1"
543         },
544         {
545                 "dpms", _tdm_monitor_server_dpms,
546                 "set output dpms", "<output_idx>:<dpms>", "0:3 or 0:0"
547         },
548         {
549                 "ttrace_vblank", _tdm_monitor_server_ttrace_vblank,
550                 "enable/disable the vblank for ttrace [0:disable, 1:server, 2:clients]",
551                 "<enable>[@<output_idx>]", "0 or 1 or 2 or 1@0 or 2@0 or 1@1 or 2@1"
552         },
553         {
554                 "debug", _tdm_monitor_server_debug,
555                 "set the debug level and modules(module: none, mutex, buffer, thread, vblank)",
556                 "<level>[@<module1>[,<module2>]]",
557                 NULL
558         },
559         {
560                 "log_path", _tdm_monitor_server_log_path,
561                 "set the log path (console,dlog,filepath)",
562                 "<path>",
563                 "console"
564         },
565         {
566                 "choose_commit_per_vblank_mode", _tdm_monitor_server_choose_commit_per_vblank_mode,
567                 "choose a commit_per_vblank mode for the output",
568                 "<output_idx> <mode>",
569                 "0 1 or 1 2 or 2 0"
570         },
571         {
572                 "fps", _tdm_monitor_server_fps,
573                 "enable/disable to print fps",
574                 "<enable>",
575                 "0 or 1"
576         },
577         {
578                 "vblank_list", _tdm_monitor_server_vblank_list,
579                 "print the client vblank list",
580                 NULL,
581                 NULL
582         },
583         {
584                 "vblank_fps", _tdm_monitor_server_vblank_fps,
585                 "set the client vblank fps for the given process ID and client vblank name",
586                 "<pid>[,<vblank_name>]@<fps>",
587                 NULL
588         },
589         {
590                 "global_fps", _tdm_monitor_server_global_fps,
591                 "set the global vblank fps for the entire system",
592                 "<fps>",
593                 NULL
594         },
595         {
596                 "prop", _tdm_monitor_server_prop,
597                 "set the property of a output or a layer",
598                 "<output_idx>[,<layer_idx>]:<prop_name>,<value>",
599                 NULL
600         },
601         {
602                 "dump", _tdm_monitor_server_dump,
603                 "dump buffers (type: none, layer, pp, capture, current)\n"
604                 "\t\t  layer, pp, capture - start to dump buffers of layer, pp, capture\n"
605                 "\t\t  none               - stop to dump buffers\n"
606                 "\t\t  current            - dump the current buffer of all layers",
607                 "<object_type1>[,<object_type2>[,...]][@<directory_path>]",
608                 NULL
609         },
610         {
611                 "punch", _tdm_monitor_server_punch,
612                 "punch a layer",
613                 "<output_idx>,<layer_idx>[:<w>x<h>[+<x>+<y>]]",
614                 NULL
615         },
616 };
617
618 static void
619 _tdm_monitor_server_usage(char *app_name, char *reply, int *len)
620 {
621         int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
622         int i;
623
624         TDM_SNPRINTF(reply, len, "usage: %s \n\n", app_name);
625
626         for (i = 0; i < opt_size; i++) {
627                 TDM_SNPRINTF(reply, len, "\t-%s\t%s\n", option_proc[i].opt, option_proc[i].desc);
628                 if (option_proc[i].arg)
629                         TDM_SNPRINTF(reply, len, "\t\t  %s\n", option_proc[i].arg);
630                 if (option_proc[i].ex)
631                         TDM_SNPRINTF(reply, len, "\t\t  ex) %s\n", option_proc[i].ex);
632                 TDM_SNPRINTF(reply, len, "\n");
633         }
634 }
635
636 static void
637 _tdm_monitor_server_command(unsigned int pid, char *cwd, tdm_display *dpy, int argc, char *argv[], char *reply, int *len)
638 {
639         int opt_size = sizeof(option_proc) / sizeof(option_proc[0]);
640         int i;
641
642         if (argc < 2) {
643                 _tdm_monitor_server_usage(argv[0], reply, len);
644                 return;
645         }
646
647         for (i = 0; i < opt_size; i++) {
648                 if (argv[1][0] == '-' && !strncmp(argv[1] + 1, option_proc[i].opt, 32)) {
649                         if (option_proc[i].func) {
650                                 option_proc[i].func(pid, cwd, argc, argv, reply, len, dpy);
651                                 return;
652                         } else {
653                                 TDM_SNPRINTF(reply, len, "'%s' not implemented.\n", argv[1]);
654                                 return;
655                         }
656                 }
657         }
658
659         _tdm_monitor_server_usage(argv[0], reply, len);
660         return;
661 }
662
663
664 INTERN void
665 tdm_monitor_server_command(tdm_display *dpy, const char *options, char *reply, int *len)
666 {
667         unsigned int pid;
668         char cwd[1024];
669         int argc = 0;
670         char *argv[TDM_DBG_SERVER_ARGS_MAX] = {0,};
671         char temp[1024];
672         char *arg;
673         char *end = NULL, *e;
674
675         snprintf(temp, sizeof(temp), "%s", options);
676
677         arg = strtok_r(temp, " ", &end);
678         if (!arg) {
679                 TDM_SNPRINTF(reply, len, "no pid for tdm-monitor");
680                 return;
681         }
682         pid = strtol(arg, &e, 10);
683
684         arg = strtok_r(NULL, " ", &end);
685         if (!arg) {
686                 TDM_SNPRINTF(reply, len, "no cwd for tdm-monitor");
687                 return;
688         }
689         snprintf(cwd, sizeof(cwd), "%s", arg);
690
691         TDM_DBG("pid(%d) cwd(%s)", pid, cwd);
692
693         argv[argc] = strtok_r(NULL, " ", &end);
694         while (argv[argc]) {
695                 argc++;
696                 if (argc == TDM_DBG_SERVER_ARGS_MAX) {
697                         TDM_SNPRINTF(reply, len, "too many arguments for tdm-monitor");
698                         break;
699                 }
700                 argv[argc] = strtok_r(NULL, " ", &end);
701         }
702
703         _tdm_monitor_server_command(pid, cwd, dpy, argc, argv, reply, len);
704 }