7 Commits 9d0f5ab98c ... c5c5533757

Autore SHA1 Messaggio Data
  rosa c5c5533757 Add Makefile 8 anni fa
  rosa 15c3731972 Add build script 8 anni fa
  alimiracle e0333f741e fix fork 8 anni fa
  alimiracle a9b1c286da make it tru daemon 8 anni fa
  alimiracle 8a694b4671 fix 2 string commit 8 anni fa
  alimiracle 8dd762ff62 add configuration system 8 anni fa
  alimiracle 3d52d20e3b add build dir 8 anni fa
5 ha cambiato i file con 66 aggiunte e 19 eliminazioni
  1. 15 0
      Makefile
  2. 5 0
      build.sh
  3. 6 0
      config.sh
  4. 30 13
      f.c
  5. 10 6
      run.sh

+ 15 - 0
Makefile

@@ -0,0 +1,15 @@
+all: f.c
+	gcc -g -Wall -o f f.c
+clean: 
+	$(RM) f
+install:
+	mkdir /etc/f
+	cp f /bin
+	cp run.sh /bin
+	cp config.sh /etc/f
+	cp build.sh /etc/f
+	chmod +x /etc/f/config.sh
+	chmod +x /etc/f/build.sh
+	chmod +x /bin/f
+	chmod +x /bin/run.sh
+.ONESHELL:

+ 5 - 0
build.sh

@@ -0,0 +1,5 @@
+list=`ls`
+if echo "$list" | grep -q "configure"; then
+chmod +x configure
+fi
+make

+ 6 - 0
config.sh

@@ -0,0 +1,6 @@
+# This is Configuration File for fun_app
+email=yourmail
+build_path="mypath"
+repository="rp"
+temp="/tmp"
+

+ 30 - 13
f.c

@@ -6,14 +6,18 @@
 #include <fcntl.h>
 #include <syslog.h>
 #include <unistd.h>
+#include <signal.h>
 int main(int argc, char *argv[])
 {
+ /* Open a connection to the syslog server */
  openlog(argv[0],LOG_NOWAIT|LOG_PID,LOG_USER);
+        /* Fork off the parent process */       
  pid_t pid;
  pid = fork();
  /* If the pid is less than zero, something went wrong when forking */
  if (pid < 0) 
 {
+/* Now we will tel the  log server  cant fork*/
  syslog(LOG_NOTICE, "Cant Fork\n");
  exit(EXIT_FAILURE);
  }
@@ -23,27 +27,40 @@ if (pid > 0)
  exit(EXIT_SUCCESS);
  }
  /* If execution reaches this point we are the child */
+/* Creating a Unique Session ID (SID)*/
+    if (setsid() < 0)
+ syslog(LOG_NOTICE, "I cant Creat a Unique Session ID ");
+        exit(EXIT_FAILURE);
+    //catch/ignore signals
+    signal(SIGCHLD,SIG_IGN);
+    signal(SIGHUP,SIG_IGN);
+        /* Fork off the parent process */
+pid_t pid1;
+ pid1 = fork();
+ /* If the pid1 is less than zero, something went wrong when forking */
+ if (pid1 < 0) 
+{
+/* Now we will tel the  log server  cant fork*/
+ syslog(LOG_NOTICE, "Cant Fork\n");
+ exit(EXIT_FAILURE);
+ }
+ /* If the pid1 we got back was greater than zero, then the clone was successful and we are the parent. */ 
+if (pid1 > 0)
+ {
+ exit(EXIT_SUCCESS);
+ }
  /* Now we will Set the umask to zero */ 
 umask(0);
- /* Now we will  create our own process group */
- pid_t sid;
- /* Try to create our own process group */
- sid = setsid();
-/* its seme ok now/*
+/* its seme ok now*/
  /* Now we will Change the current working directory to root */
  chdir("/");
-/* Close all io /*
+/* Close all Files */
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
-    //catch/ignore signals
-    signal(SIGCHLD,SIG_IGN);
-    signal(SIGHUP,SIG_IGN);
-
 /* Now we will tel the log server its ok now */
- /* Open a connection to the syslog server */
- /* Sends a message to the syslog daemon */
  syslog(LOG_NOTICE, "Successfully started daemon\n");
+ /* close a connection to the syslog server */
  closelog();
 /* make new file to save last commit */
 FILE *fp = fopen("scores.dat", "ab+");
@@ -51,6 +68,6 @@ fclose(fp);
 
 while (1)
 {
-system("bash /home/ali/run.sh");
+system("bash /home/clara/fun/run.sh");
 }
 }

+ 10 - 6
run.sh

@@ -1,13 +1,17 @@
-dir="/home/clara/blade"
-cd $dir
+source config.sh
+cd $repository
 log1=`git log -1 --pretty=%B`
-log2=`cat /tmp/q.txt`
+log2=`cat $temp/q.txt`
+log1_copy=$log1
     if [ "$log1" = "$log2" ]
 then
 q=1
 else
-echo $log1 >/tmp/q.txt
+echo $log1 >$temp/q.txt
+remove_char="_"
+log1=${log1//" "/$remove_char}
+cp -R $repository $build_path/$log1
+cd $build_path/$log1
 make &>/tmp/q.tmp
-echo "this build log for "$log1|mutt -a /tmp/q.tmp -s "build log" -- blade.vp2020@gmail.com
-make clean
+echo "this build log for "$log1_copy|mutt -a /tmp/q.tmp -s "build log" -- $email
 fi