Re: [hackers] Re: [dwm][PATCH] Proper restart function

From: toluschr <toluschr_AT_protonmail.com>
Date: Mon, 08 Mar 2021 17:12:50 +0000

On Monday, March 8, 2021 2:49 PM, Hiltjo Posthuma <hiltjo_AT_codemadness.org> wrote:

> On Mon, Mar 08, 2021 at 11:29:12AM +0000, Tolu2 wrote:
>
> > On Saturday, March 6, 2021 4:59 PM toluschr wrote:
> >
> > > The currently available patch reads /proc/self/exe, which fails when recompiling (Why else would I want to restart dwm?)
> > > This patch simply saves the commandline arguments on startup and re-executes them.
> > >
> > > dwm.c | 12 +++++++++++-
> > > 1 file changed, 11 insertions(+), 1 deletion(-)
> > > diff --git a/dwm.c b/dwm.c
> > > index 664c527..9e8160f 100644
> > > --- a/dwm.c
> > > +++ b/dwm.c
> > > _AT_@ -234,6 +234,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
> > > static int xerrordummy(Display *dpy, XErrorEvent *ee);
> > > static int xerrorstart(Display *dpy, XErrorEvent *ee);
> > > static void zoom(const Arg *arg);
> > > +static void restart(const Arg arg);
> > > / variables */static const char broken[] = "broken";
> > > _AT_@ -268,6 +269,7 @@ static Display *dpy;
> > > static Drw *drw;
> > > static Monitor *mons, *selmon;
> > > static Window root, wmcheckwin;
> > > +static char *argv;
> > > / configuration, allows nested code to access above variables */#include "config.h"
> > > _AT_@ -2127,9 +2129,17 @@ zoom(const Arg *arg)
> > > pop(c);
> > > }
> > > +void
> > > +restart(const Arg *arg)
> > > +{
> > >
> > > - execvp(argv[0], argv);
> > > +}
> > >
> > > -
> > >
> > > int
> > > -main(int argc, char *argv[])
> > > +main(int argc, char *_argv[])
> > > {
> > >
> > > - argv = _argv;
> > > - if (argc == 2 && !strcmp("-v", argv[1]))
> > > die("dwm-"VERSION);
> > > else if (argc != 1)
> > >
> > > ---------------------------------------------------------------------------------
> > >
> > > 2.30.1
> > >
> >
> > I noticed that it might not have been clear that my intention was to have this included in the mainline. Since there is a quit function, why not also have a restart? It makes edits to the source code much more pleasant.
>
> Hi,
>
> I don't think the patch makes much sense. It can be solved by running dwm in
> some loop and just exiting or killing dwm for example.
>
> Indeed, patches to hackers_AT_ are intended for upstream as described on:
> http://suckless.org/community/
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Kind regards,
> Hiltjo

Hi, thanks for the response.

As far as I know, dwm always returns 0 when it quits (So the loop wouldn't know when to stop / restart).
This requires spawning an external process to kill it (or changing the source) when binding restart to a key.
Optionally, the `quit` function could use it's parameter as the exit code.

It's a very trivial change. Do you think submitting this to the /patches site would make sense?
Received on Mon Mar 08 2021 - 18:12:50 CET

This archive was generated by hypermail 2.3.0 : Mon Mar 08 2021 - 18:24:34 CET