]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
command: Add sleep
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Aug 2022 20:53:29 +0000 (20:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Aug 2022 20:53:29 +0000 (20:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/stub/command.c

index 0c0fd306852a1130ad960344a94f3db24781421d..9c9dc27f8af810bd6fb920bba541d5e7f4e6e832 100644 (file)
@@ -244,6 +244,23 @@ static int send_signal(int argc, char* argv[]) {
        return EXIT_SUCCESS;
 }
 
+static int _sleep(int argc, char* argv[]) {
+       if (argc < 1) {
+               fprintf(stderr, "No timeout given\n");
+               return EXIT_FAILURE;
+       }
+
+       // Fetch timeout
+       unsigned int timeout = strtoul(argv[0], NULL, 10);
+
+       printf("Sleeping for %u second(s)\n", timeout);
+
+       // Sleep for given timeout
+       sleep(timeout);
+
+       return EXIT_SUCCESS;
+}
+
 int main(int argc, char* argv[]) {
        if (argc < 2) {
                fprintf(stderr, "No command given\n");
@@ -292,6 +309,10 @@ int main(int argc, char* argv[]) {
        else if (strcmp(command, "send-signal") == 0)
                callback = send_signal;
 
+       // Sleep
+       else if (strcmp(command, "sleep") == 0)
+               callback = _sleep;
+
        // Exit if no callback has been set
        if (!callback) {
                fprintf(stderr, "Unknown command: %s\n", command);