-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.cpp
47 lines (37 loc) · 908 Bytes
/
commands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// Created by jonas on 12.03.16.
//
#include <unistd.h>
#include <string.h>
#include <iostream>
#include "commands.h"
int update(int argc, vector<string> argv, string from)
{
char path[256];
char dest[256];
pid_t pid = getpid();
sprintf(path, "/proc/%d/exe", pid);
memset(dest, '\0',256);
if (readlink(path, dest, 256) == -1)
perror("readlink");
char* args[2];
args[0] = dest;
args[1] = NULL;
char mystring [100];
FILE *command = popen("git pull", "r");
while(fgets (mystring , 100 , command) != NULL)
cout << mystring;
pclose(command);
cout << dest << endl;
unlink(dest);
command = popen("cmake .. && make", "r");
while(fgets (mystring , 100 , command) != NULL)
cout << mystring;
pclose(command);
if( execv(dest, args) == -1)
{
fprintf(stderr, "Failed to reexecute %s %d %s\n", dest, errno, strerror(errno));
}
return 0;
exit(1);
}