proc_cmdline.c 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include "proc.h"
  10. #include "procfs.h"
  11. #include <rthw.h>
  12. #include <rtdbg.h>
  13. #include <fcntl.h>
  14. #include <errno.h>
  15. #include <dfs_dentry.h>
  16. static char *__proc_cmdline = NULL;
  17. int proc_cmdline_save(const char *cmdline)
  18. {
  19. if (__proc_cmdline)
  20. {
  21. free(__proc_cmdline);
  22. __proc_cmdline = NULL;
  23. }
  24. __proc_cmdline = strdup(cmdline);
  25. return 0;
  26. }
  27. static int single_show(struct dfs_seq_file *seq, void *data)
  28. {
  29. if (__proc_cmdline)
  30. {
  31. dfs_seq_puts(seq, __proc_cmdline);
  32. }
  33. return 0;
  34. }
  35. int proc_cmdline_init(void)
  36. {
  37. struct proc_dentry *dentry = proc_create_single_data("cmdline", 0, NULL, single_show, NULL);
  38. proc_release(dentry);
  39. return 0;
  40. }
  41. INIT_ENV_EXPORT(proc_cmdline_init);