]> git.sesse.net Git - nageru/blobdiff - futatabi/main.cpp
On errors, abort() instead of exit(1); exit() in a multithreaded program just gives...
[nageru] / futatabi / main.cpp
index 4c54d332d24951b9118798b86c90ef3ab10e464b..e6556d37aa91bff568111d4da8cadc4e609f8ac5 100644 (file)
@@ -84,7 +84,7 @@ FrameOnDisk write_frame(int stream_idx, int64_t pts, const uint8_t *data, size_t
                FILE *fp = fopen(filename, "wb");
                if (fp == nullptr) {
                        perror(filename);
-                       exit(1);
+                       abort();
                }
 
                lock_guard<mutex> lock(frame_mu);
@@ -109,26 +109,26 @@ FrameOnDisk write_frame(int stream_idx, int64_t pts, const uint8_t *data, size_t
        string serialized;
        if (!hdr.SerializeToString(&serialized)) {
                fprintf(stderr, "Frame header serialization failed.\n");
-               exit(1);
+               abort();
        }
        uint32_t len = htonl(serialized.size());
 
        if (fwrite(frame_magic, frame_magic_len, 1, file.fp) != 1) {
                perror("fwrite");
-               exit(1);
+               abort();
        }
        if (fwrite(&len, sizeof(len), 1, file.fp) != 1) {
                perror("fwrite");
-               exit(1);
+               abort();
        }
        if (fwrite(serialized.data(), serialized.size(), 1, file.fp) != 1) {
                perror("fwrite");
-               exit(1);
+               abort();
        }
        off_t offset = ftell(file.fp);
        if (fwrite(data, size, 1, file.fp) != 1) {
                perror("fwrite");
-               exit(1);
+               abort();
        }
        fflush(file.fp);  // No fsync(), though. We can accept losing a few frames.
        global_disk_space_estimator->report_write(filename, 8 + sizeof(len) + serialized.size() + size, pts);
@@ -151,7 +151,7 @@ FrameOnDisk write_frame(int stream_idx, int64_t pts, const uint8_t *data, size_t
                // Start a new file next time.
                if (fclose(file.fp) != 0) {
                        perror("fclose");
-                       exit(1);
+                       abort();
                }
                open_frame_files.erase(stream_idx);
 
@@ -199,7 +199,7 @@ int main(int argc, char **argv)
                global_flags.stream_source = argv[optind];
        } else {
                usage();
-               exit(1);
+               abort();
        }
 
        string frame_dir = global_flags.working_directory + "/frames";
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
                fprintf(stderr, "%s does not exist, creating it.\n", frame_dir.c_str());
        } else if (errno != EEXIST) {
                perror(global_flags.working_directory.c_str());
-               exit(1);
+               abort();
        }
 
        avformat_network_init();
@@ -237,7 +237,7 @@ int main(int argc, char **argv)
        global_share_widget = new QGLWidget();
        if (!global_share_widget->isValid()) {
                fprintf(stderr, "Failed to initialize OpenGL. Futatabi needs at least OpenGL 4.5 to function properly.\n");
-               exit(1);
+               abort();
        }
 
        // Initialize Movit.
@@ -246,7 +246,7 @@ int main(int argc, char **argv)
                QOpenGLContext *context = create_context(surface);
                if (!make_current(context, surface)) {
                        printf("oops\n");
-                       exit(1);
+                       abort();
                }
                CHECK(movit::init_movit(MOVIT_SHADER_DIR, movit::MOVIT_DEBUG_OFF));
                delete_context(context);
@@ -284,7 +284,7 @@ void load_frame_file(const char *filename, const string &basename, unsigned file
        struct stat st;
        if (stat(filename, &st) == -1) {
                perror(filename);
-               exit(1);
+               abort();
        }
 
        vector<DB::FrameOnDiskAndStreamIdx> all_frames = db->load_frame_file(basename, st.st_size, filename_idx);
@@ -302,7 +302,7 @@ void load_frame_file(const char *filename, const string &basename, unsigned file
        FILE *fp = fopen(filename, "rb");
        if (fp == nullptr) {
                perror(filename);
-               exit(1);
+               abort();
        }
 
        size_t magic_offset = 0;
@@ -412,7 +412,7 @@ void load_existing_frames()
                if (de == nullptr) {
                        if (errno != 0) {
                                perror("readdir");
-                               exit(1);
+                               abort();
                        }
                        break;
                }
@@ -424,7 +424,7 @@ void load_existing_frames()
                }
 
                if (progress.wasCanceled()) {
-                       exit(1);
+                       abort();
                }
        }
        closedir(dir);
@@ -442,7 +442,7 @@ void load_existing_frames()
                load_frame_file(frame_filenames[i].c_str(), frame_basenames[i], i, &db);
                progress.setValue(i + 3);
                if (progress.wasCanceled()) {
-                       exit(1);
+                       abort();
                }
        }