[wiki] [sites] updated the selfrestart patch to be more intelligent || Barbu Paul - Gheorghe

From: <git_AT_suckless.org>
Date: Tue, 04 Dec 2012 21:02:24 +0100

commit 2ad8e2e9f006c1646e288b9cdd2cead4ddc01e95
Author: Barbu Paul - Gheorghe <barbu.paul.gheorghe_AT_gmail.com>
Date: Tue Dec 4 22:02:17 2012 +0200

    updated the selfrestart patch to be more intelligent

diff --git a/dwm.suckless.org/patches/dwm-r1615-selfrestart.diff b/dwm.suckless.org/patches/dwm-r1615-selfrestart.diff
index f0cf196..5d019b2 100644
--- a/dwm.suckless.org/patches/dwm-r1615-selfrestart.diff
+++ b/dwm.suckless.org/patches/dwm-r1615-selfrestart.diff
_AT_@ -1,35 +1,101 @@
 # HG changeset patch
 # User Barbu Paul - Gheorghe <barbu.paul.gheorghe_AT_gmail.com>
-# Date 1353844130 -7200
-# Node ID 6a057e59c31e7b831766d5abe84bdb0db868db92
-# Parent 9cace08dcb7e57f76a2206bada6fc3b9557c63dc
-Added the possibility to selfrestart dwm without external script
+# Date 1354650884 -7200
+# Node ID 6c472a21a5887c5295a331c48c4da188ec2c8413
+# Parent aaab44133a6830c9a00263731d098c01cc1d6fb5
+selfrestart now magically locates the current dwm (no need to hardcode a path)
 
-diff -r 9cace08dcb7e -r 6a057e59c31e config.def.h
---- a/config.def.h Sun Nov 18 17:52:42 2012 +0100
-+++ b/config.def.h Sun Nov 25 13:48:50 2012 +0200
-_AT_@ -1,5 +1,17 @@
- /* See LICENSE file for copyright and license details. */
+diff -r aaab44133a68 -r 6c472a21a588 config.def.h
+--- a/config.def.h Tue Dec 04 21:54:44 2012 +0200
++++ b/config.def.h Tue Dec 04 21:54:44 2012 +0200
+_AT_@ -54,6 +54,8 @@
+ static const char *termcmd[] = { "urxvtc", NULL };
+ static const char *filemancmd[] = { "thunar", NULL };
  
++#include "selfrestart.c"
++
+ static Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY, XK_r, spawn, {.v = dmenucmd } },
+_AT_@ -89,6 +91,7 @@
+ TAGKEYS( XK_7, 6)
+ TAGKEYS( XK_8, 7)
+ TAGKEYS( XK_9, 8)
++ { MODKEY|ShiftMask, XK_r, self_restart, {0} },
+ { MODKEY|ShiftMask, XK_q, quit, {0} },
+ };
+
+_AT_@ -108,4 +111,3 @@
+ { ClkTagBar, MODKEY, Button1, tag, {0} },
+ { ClkTagBar, MODKEY, Button3, toggletag, {0} },
+ };
+-
+diff -r aaab44133a68 -r 6c472a21a588 selfrestart.c
+--- /dev/null Thu Jan 01 00:00:00 1970 +0000
++++ b/selfrestart.c Tue Dec 04 21:54:44 2012 +0200
+_AT_@ -0,0 +1,65 @@
++#include <unistd.h>
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <stdio.h>
++#include <stdlib.h>
++
++/**
++ * Magically finds the current's executable path
++ *
++ * I'm doing the do{}while(); trick because Linux (what I'm running) is not
++ * POSIX compilant and so lstat() cannot be trusted on /proc entries
++ *
++ * _AT_return char* the path of the current executable
++ */
++char *get_dwm_path(){
++ struct stat s;
++ int r, length, rate = 42;
++ char *path = NULL;
++
++ if(lstat("/proc/self/exe", &s) == -1){
++ perror("lstat:");
++ return NULL;
++ }
++
++ length = s.st_size + 1 - rate;
++
++ do{
++ length+=rate;
++
++ free(path);
++ path = malloc(sizeof(char) * length);
++
++ if(path == NULL){
++ perror("malloc:");
++ return NULL;
++ }
++
++ r = readlink("/proc/self/exe", path, length);
++
++ if(r == -1){
++ perror("readlink:");
++ return NULL;
++ }
++ }while(r >= length);
++
++ path[r] = '
Received on Tue Dec 04 2012 - 21:02:24 CET

This archive was generated by hypermail 2.3.0 : Tue Dec 04 2012 - 21:12:06 CET