debug.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License version 2.1
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16. #include <fcntl.h>
  17. #include <regex.h>
  18. #include <unistd.h>
  19. #include "procd.h"
  20. unsigned int debug = 0;
  21. void debug_init(void)
  22. {
  23. char line[256];
  24. int r, fd = open("/proc/cmdline", O_RDONLY);
  25. regex_t pat_cmdline;
  26. regmatch_t matches[2];
  27. if (fd < 0)
  28. return;
  29. r = read(fd, line, sizeof(line) - 1);
  30. line[r] = '\0';
  31. close(fd);
  32. regcomp(&pat_cmdline, "init_debug=([0-9]+)", REG_EXTENDED);
  33. if (!regexec(&pat_cmdline, line, 2, matches, 0)) {
  34. line[matches[1].rm_eo] = '\0';
  35. debug = atoi(&line[matches[1].rm_so]);
  36. }
  37. regfree(&pat_cmdline);
  38. }