Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.9 KiB

  1. void
  2. runautostart(void)
  3. {
  4. char *pathpfx;
  5. char *path;
  6. char *xdgdatahome;
  7. char *home;
  8. if ((home = getenv("HOME")) == NULL)
  9. /* this is almost impossible */
  10. return;
  11. /* if $XDG_DATA_HOME is defined, use $XDG_DATA_HOME/dwm,
  12. * otherwise use ~/.local/share/dwm as autostart script directory
  13. */
  14. if ((xdgdatahome = getenv("XDG_DATA_HOME")) != NULL) {
  15. /* space for path segments, separators and nul */
  16. if ((pathpfx = malloc(strlen(xdgdatahome) + strlen(dwmdir) + 2)) == NULL)
  17. return;
  18. if (sprintf(pathpfx, "%s/%s", xdgdatahome, dwmdir) <= 0) {
  19. free(pathpfx);
  20. return;
  21. }
  22. } else {
  23. /* space for path segments, separators and nul */
  24. if ((pathpfx = malloc(strlen(home) + strlen(localshare) + strlen(dwmdir) + 3)) == NULL)
  25. return;
  26. if (sprintf(pathpfx, "%s/%s/%s", home, localshare, dwmdir) < 0) {
  27. free(pathpfx);
  28. return;
  29. }
  30. }
  31. /* check if the autostart script directory exists */
  32. struct stat sb;
  33. if (! (stat(pathpfx, &sb) == 0 && S_ISDIR(sb.st_mode))) {
  34. /* the XDG conformant path does not exist or are not directories
  35. * so we try ~/.dwm instead
  36. */
  37. if (realloc(pathpfx, strlen(home) + strlen(dwmdir) + 3) == NULL) {
  38. free(pathpfx);
  39. return;
  40. }
  41. if (sprintf(pathpfx, "%s/.%s", home, dwmdir) <= 0) {
  42. free(pathpfx);
  43. return;
  44. }
  45. }
  46. /* try the blocking script first */
  47. if ((path = malloc(strlen(pathpfx) + strlen(autostartblocksh) + 2)) == NULL) {
  48. free(pathpfx);
  49. return;
  50. } else
  51. if (sprintf(path, "%s/%s", pathpfx, autostartblocksh) <= 0) {
  52. free(path);
  53. free(pathpfx);
  54. }
  55. if (access(path, X_OK) == 0)
  56. system(path);
  57. /* now the non-blocking script */
  58. if ((path = realloc(path, strlen(pathpfx) + strlen(autostartsh) + 4)) == NULL) {
  59. free(pathpfx);
  60. free(path);
  61. return;
  62. } else
  63. if (sprintf(path, "%s/%s", pathpfx, autostartsh) <= 0) {
  64. free(path);
  65. free(pathpfx);
  66. }
  67. if (access(path, X_OK) == 0) {
  68. system(strcat(path, " &"));
  69. free(pathpfx);
  70. free(path);
  71. }
  72. }