commit 23244bdedd5a4a9b36a01a1111e2aa41ecfa6d6f
parent 12f92e7aeff3d31545753de8d6c9678cb2c914bd
Author: Jaromil <jaromil@dyne.org>
Date:   Wed,  9 Feb 2011 20:35:11 +0100
fixes to tomb-status
Diffstat:
| M | src/tomb-open |  |  | 93 | ++++++++++++++++++++++++++++++++++++++++++------------------------------------- | 
| M | src/tomb-status.c |  |  | 49 | +++++++++++++++++++++++++++++++++++-------------- | 
2 files changed, 85 insertions(+), 57 deletions(-)
diff --git a/src/tomb-open b/src/tomb-open
@@ -1,4 +1,4 @@
-#!/bin/zsh
+#!/bin/zsh -x
 #
 # Tomb, the Crypto Undertaker
 #
@@ -23,48 +23,63 @@
 # startup wrapper to open tombs
 
 
+echo "arg: $1"
+
 try() {
     which ${1} > /dev/null
     if [ $? = 0 ]; then return 0;
     else return -1; fi
 }
 	
-# if no arguments are given, run in terminal 
-if [ -z $1 ]; then
-    try gnome-terminal; if [ $? = 0 ]; then gnome-terminal -e "tomb-open create"; exit 0; fi
-    try lxterm; if [ $? = 0 ]; then lxterm -bg black -fg white -e "tomb-open create"; exit 0; fi
-    try urxvt; if [ $? = 0 ]; then urxvt -bg black -fg white -e "tomb-open create"; exit 0; fi
-    try uxterm; if [ $? = 0 ]; then uxterm -bg black -fg white -e "tomb-open create"; exit 0; fi
-    try xterm; if [ $? = 0 ]; then xterm -bg black -fg white -e "tomb-open create"; exit 0; fi
-    exit 1
-fi
 
 
-# got a directory as argument
-if [ -d $1 ]; then
+
+# got an argument
+if [ $1 ]; then
+# is it a tomb?
+    arg="${1%%\.*}.tomb"
+
+    if [ -f $arg ]; then
+	file $arg | grep LUKS
+
+	if [ $? = 0 ]; then # tomb is a valid LUKS file
+
+	    tomb mount $arg
+
+	    if [ $? = 0 ]; then	# mount was succesfull (with password and all)
+	    # strip extension if there
+		tombname="${arg%%.*}"
+		tombmap=`mount -l | awk "/\[${tombname}\]$/"' { print $1 } '`
+		tombmount=`mount -l | awk "/\[${tombname}\]$/"' { print $3 } '`
+		tomb-status $tombmap $tombname $tombmount &!
+		exit 0
+	    else
+		tomb notify "Tomb cannot open." "Are you knocking the wrong door?"
+		exit 1
+	    fi
+	else
+	    tomb notify "Not a real Tomb." "We found no real bones in there."
+	    exit 1
+	fi
+
+
+    elif [ -d $1 ]; then
+	# its a directory
+	
 # FIXME: somehow xdg-open loses mailcap mimes when executed by tomb-status
 #   try xdg-open; if [ $? = 0 ]; then xdg-open ${1}; exit 0; fi
-    try gnome-open; if [ $? = 0 ]; then gnome-open ${1}; exit 0; fi
-    try thunar; if [ $? = 0 ]; then thunar ${1}; exit 0; fi
-    try rox; if [ $? = 0 ]; then rox ${1}; exit 0; fi
-    try fsviewer; if [ $? = 0 ]; then fsviewer ${1}; exit 0; fi
-    try xnc; if [ $? = 0 ]; then xnc ${1}; exit 0; fi
-    tomb notify "File manager not found." "Tomb cannot guess which filemanager you are using"
-    exit 1
-fi
-
-# got a tomb as argument?
-if [ -f $1 ]; then
-    file $1 | grep LUKS
-    if [ $? = 0 ]; then
-	tomb mount $1
-	exit $?
-    else
-	tomb notify "Not a real Tomb." "We found no real bones in there."
+	try gnome-open; if [ $? = 0 ]; then gnome-open ${1}; exit 0; fi
+	try thunar; if [ $? = 0 ]; then thunar ${1}; exit 0; fi
+	try pcmanfm; if [ $? = 0 ]; then pcmanfm ${1}; exit 0; fi	
+	try rox; if [ $? = 0 ]; then rox ${1}; exit 0; fi
+	try fsviewer; if [ $? = 0 ]; then fsviewer ${1}; exit 0; fi
+#	try xnc; if [ $? = 0 ]; then xnc ${1}; exit 0; fi
+	tomb notify "File manager not found." "Tomb cannot guess which filemanager you are using"
 	exit 1
     fi
 fi
 
+
 # no argument but on graphical display: creation dialog
 if [ -z $DISPLAY ]; then
     echo "[!] tomb-open is a wrapper for the command 'tomb'"
@@ -72,11 +87,7 @@ if [ -z $DISPLAY ]; then
     exit 1
 fi
 
-if [ "$1" != "create" ]; then
-    exit 0
-fi
-
-# start guided tomb creation
+# no arguments: start guided tomb creation
 tomb notify
 cat <<EOF
 Create a new Tomb
@@ -134,15 +145,11 @@ tomb create ${filename}.tomb $size
 
 if [ $? != 0 ]; then
     echo "An error occurred creating tomb, operation aborted."
-    tomb kill
-    echo "Press any key to close this terminal."
-    read -q
     exit 1
 fi
-if ! [ -r /usr/share/applications/tomb.desktop ]; then
-    echo "  Well done!"
-    echo "  Now the last thing to do is to install Tomb on your desktop:"
-    sudo tomb install
-fi
+# if ! [ -r /usr/share/applications/tomb.desktop ]; then
+#     echo "  Well done!"
+#     echo "  Now the last thing to do is to install Tomb on your desktop:"
+#     sudo tomb install
+# fi
 
-exit 0
diff --git a/src/tomb-status.c b/src/tomb-status.c
@@ -145,27 +145,39 @@ gboolean left_click(GtkWidget *w, GdkEvent *e) {
   return TRUE;
 } 
 gboolean cb_view(GtkWidget *w, GdkEvent *e) { 
-  // GtkWidget *dialog = 
-  //   gtk_message_dialog_new (NULL,
-  // 			    GTK_DIALOG_DESTROY_WITH_PARENT,
-  // 			    GTK_MESSAGE_INFO,
-  // 			    GTK_BUTTONS_CLOSE,
-  // 			    "Tomb '%s' open on '%s'\n"
-  // 			    "device mapper: %s", filename, mountpoint, mapper);
-  // gtk_dialog_run (GTK_DIALOG (dialog));
-  // gtk_widget_destroy (dialog);
-  pid_t cpid = fork();
+  int pipefd[2];
+  pid_t cpid;
+  char buf;
+  int c, res;
+  char map[256];
+
+  if (pipe(pipefd) <0) {
+    fprintf(stderr,"pipe creation error: %s\n", strerror(errno));
+    return FALSE;
+  }
+
+  cpid = fork();
   if (cpid == -1) {
-    fprintf(stderr,"error: problem forking process\n");
+    fprintf(stderr,"fork error: %s\n", strerror(errno));
     return FALSE;
   }
   if (cpid == 0) {    // Child
-    execlp("tomb-open", "tomb-open", mountpoint ,(char*)NULL);
-    exit(1);
+    close(pipefd[1]); // close unused write end
+    for(c=0; read(pipefd[0], &buf, 1) > 0; c++)
+      map[c] = buf;
+    close(pipefd[0]);
+    map[c] = 0;
+    execlp("tomb-open", "tomb-open", map, (char*)NULL);
+    _exit(1);
   }
+  close(pipefd[0]); // close unused read end
+  write(pipefd[1], mountpoint, strlen(mountpoint));
+  close(pipefd[1]); // reader will see EOF
+
   return TRUE;
 }
 
+
 gboolean cb_close(GtkWidget *w, GdkEvent *e) { 
   int pipefd[2];
   pid_t cpid;
@@ -189,7 +201,7 @@ gboolean cb_close(GtkWidget *w, GdkEvent *e) {
     for(c=0; read(pipefd[0], &buf, 1) > 0; c++)
       map[c] = buf;
     close(pipefd[0]);
-    map[c] = '\n';
+    map[c] = 0;
     execlp("tomb", "tomb", "close", map, (char*)NULL);
     _exit(1);
   }
@@ -257,3 +269,12 @@ gboolean cb_about(GtkWidget *w, GdkEvent *e) {
 }
   
 
+  // GtkWidget *dialog = 
+  //   gtk_message_dialog_new (NULL,
+  // 			    GTK_DIALOG_DESTROY_WITH_PARENT,
+  // 			    GTK_MESSAGE_INFO,
+  // 			    GTK_BUTTONS_CLOSE,
+  // 			    "Tomb '%s' open on '%s'\n"
+  // 			    "device mapper: %s", filename, mountpoint, mapper);
+  // gtk_dialog_run (GTK_DIALOG (dialog));
+  // gtk_widget_destroy (dialog);