Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Application: basic-webserver, Helpers.cpp
- * Author: Project, UNX511, Team A
- * Description: Contains helper functions
- * A webserver that has been coded from scratch.
- * It uses Linux's socket library to deal with connections.
- *
- * This application is licensed under Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
- * See this for more information: http://creativecommons.org/licenses/by-nc-sa/3.0/
- */
- #include "Helpers.h"
- void preventZombies() {
- signal(SIGHUP, SIG_IGN); // Ignore terminal hangups
- signal(SIGCLD, SIG_IGN); // Ignore child death
- setpgrp(); // Break away from process group
- }
- char* runCmd(const char* cmd){
- FILE* fp;
- char* out = NULL;
- char* more_out;
- char ch;
- int count = 0;
- /* Open the command for reading. */
- fp = popen(cmd, "r");
- if (fp == NULL) {
- printf("Failed to run command\n" );
- return 0;
- }
- /* Read the output a line at a time - output it. */
- ch = fgetc(fp);
- while(ch != '\n' && ch != EOF){
- more_out = (char*) realloc(out, ++count); // no need to free more_out
- if(more_out != NULL){
- out = more_out;
- out[count-1] = ch;
- }
- ch = fgetc(fp);
- }
- pclose(fp);
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement