📄 ptt_level.c
字号:
/* Copyright (C) 2004,2005,2006 Bull S.A. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#if HAVE_CONFIG_H#include <config.h>#endif#define _XOPEN_SOURCE 500#include <string.h>#include <stdio.h>#include <fcntl.h>#include <stdlib.h>#include <sys/mman.h>#include "types.h"#include "level.h"#define PTT_FILE_LEN 255struct ptt_buffer * ptt_buf;static void usage (void) { printf("ptt-level -p pgid -l level\n" "Help :\n" "\t-l level:\tchange the trace level(default all)\n" "\t-p pgid:\tset the pgid of the process\n" "\t-h:\t\tthis help\n"); exit (1);}int main (int argc, char**argv) { pid_t pgid = 0; char region [PTT_FILE_LEN]; /* name of the shared memory */ int fd; unsigned int trace_level = PTT_LEVEL_ALL; signed char c; const char * optstring = "+hl:p:"; char *level_str = (char *)""; while ((c = getopt (argc, argv, optstring)) != EOF) { switch (c) { case 'h': usage (); break; case 'l': trace_level = PTT_LEVEL_NONE; level_str = strdup (optarg); while (optarg) { char *level = optarg; strsep (&optarg, ","); trace_level |= levelstr2int (level); } break; case 'p': pgid = strtol (optarg, NULL, 10); break; case '?': printf ("error : %c\n", optopt); usage(); } } if (pgid == 0) { printf("pgid not set\n"); usage(); exit (1); } snprintf (region, sizeof (region), "/ptt_%d", pgid); if ((fd = shm_open (region, O_RDWR, S_IRUSR | S_IWUSR)) == -1) { perror("shm_open failed (probably wrong pgid)"); abort(); } /* map the shared memory */ if ((ptt_buf = mmap (0, sizeof (struct ptt_buffer), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { perror ("mmap failed"); abort (); } ptt_buf->current_level = trace_level; printf("*** level %s = %d\n", level_str, trace_level); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -