Skip to content

Commit

Permalink
migrate to pthread.h
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaGanzin committed Mar 18, 2023
1 parent d740d6d commit 9ed7588
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 298 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
curl https://i.jpillora.com/slavaGanzin/await! | bash
```

### macOS install
```
curl -L https://github.com/slavaGanzin/await/releases/download/0.9/await-macos -o /usr/local/bin/await
chmod +x /usr/local/bin/await
```

# With await you can:
### Take action on specific file type changes
```bash
Expand Down
20 changes: 7 additions & 13 deletions await.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
#include <getopt.h>
#include <sys/stat.h>
#include <syslog.h>
#ifdef __APPLE__
#include "threads.h"
#else
#include <threads.h>
#endif

#include <pthread.h>
#include <pwd.h>
#include <limits.h>

Expand All @@ -25,7 +20,7 @@ typedef struct {
size_t outPos;
int status;
int change;
thrd_t thread;
pthread_t thread;
} COMMAND;

COMMAND c[100];
Expand Down Expand Up @@ -316,7 +311,7 @@ int service() {
system(replace("SERVICE", service, "systemctl --user daemon-reload; systemctl cat --user SERVICE; systemctl enable --user SERVICE; systemctl restart --user SERVICE; journalctl --user --follow --unit SERVICE"));
}

int shell(void * arg) {
void *shell(void * arg) {
COMMAND *c = (COMMAND*)arg;
c->out = malloc(CHUNK_SIZE * sizeof(char));
strcpy(c->out, "");
Expand Down Expand Up @@ -351,13 +346,12 @@ int shell(void * arg) {
if (args.daemonize) syslog(LOG_NOTICE, "%d %s", c->status, c->command);
msleep(args.interval);
}
return 0;
}


int main(int argc, char *argv[]) {
pid_t sessionid = setsid();
thrd_t exec_thread;
pthread_t exec_thread;

parse_args(argc, argv);
if (args.service) return service();
Expand All @@ -367,7 +361,7 @@ int main(int argc, char *argv[]) {

for(int i = 0; i < args.nCommands; i++) {
c[i].status = -1;
thrd_create(&c[i].thread, shell, &c[i]);
pthread_create(&c[i].thread, NULL, shell, &c[i]);
}

int not_done;
Expand Down Expand Up @@ -398,13 +392,12 @@ int main(int argc, char *argv[]) {
if (args.exec) {
exec.command = args.exec;
exec.spinner = 1;
thrd_create(&exec_thread, shell, &exec);
pthread_create(&exec_thread, NULL, shell, &exec);
}
if (!args.forever) {
while (1) {
int color = exec.status == -1 ? 7 : exec.status == args.expectedStatus ? 2 : 1;
fprintf(stderr, "\r");
msleep(args.interval);
if (exec.out) {
printf("%s", exec.out);
strcpy(exec.out, "");
Expand All @@ -413,6 +406,7 @@ int main(int argc, char *argv[]) {
}
if (exec.spinner == 0) {
exit(0);
return 0;
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ $(du -h await | sed 's/\s.*//')b, small memory footprint, single binary that run
curl https://i.jpillora.com/slavaGanzin/await! | bash
\`\`\`
### macOS install
\`\`\`
curl -L https://github.com/slavaGanzin/await/releases/download/0.9/await-macos -o /usr/local/bin/await
chmod +x /usr/local/bin/await
\`\`\`
# With await you can:
### Take action on specific file type changes
\`\`\`bash
Expand Down
273 changes: 0 additions & 273 deletions threads.h

This file was deleted.

0 comments on commit 9ed7588

Please sign in to comment.