bugmake - Bugs: bug #63219, Introduce a close function for...

 
 

bug #63219: Introduce a close function for loadable plugins.

Submitter:  Dmitry Goncharov <dgoncharov>
Submitted:  Sun 16 Oct 2022 12:17:42 AM UTC
   
 
Severity:  3 - Normal Item Group:  Enhancement
Status:  Fixed Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  4.4 Operating System:  None
Fixed Release:  SCM Triage Status:  Medium Effort
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 14 May 2023 10:34:59 PM UTC, comment #4: 

I added an implementation but I changed the name to "unload" and reworked parts of the implementation.

I also created a API/ABI version value but couldn't find a backward-compatible way to implement it, that I liked.  So, it's a change in the API.  If anyone has a good idea of a better way to do it please let me know.

It is possible, via preprocessor statements, to implement a loadable module that will work with both old and new APIs.  But unfortunately modules written for the old API won't work with the new one.

Paul D. Smith <psmith>
Group administrator
Sun 16 Oct 2022 05:49:04 AM UTC, comment #3: 

If we are going to extend the API of the loadable modules, I think we will have to introduce API versions, because the new API will be binary-incompatible with the old one, and Make should refuse to load modules that are incompatible with the API for which it was built.

Eli Zaretskii <eliz>
Group Member
Sun 16 Oct 2022 12:45:20 AM UTC, comment #2: 

This is the example from the manual extended with a close function




#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#include <gnumake.h>

int plugin_is_GPL_compatible;

struct file {
  struct file *next;
  char *name;
};
static struct file *files = NULL;

static char *
gen_tmpfile (const char *nm, int argc, char **argv)
{
  int fd;

  /* Compute the size of the filename and allocate space for it.  */
  int len = strlen (argv[0]) + 6 + 1;
  char *buf = gmk_alloc (len);

  strcpy (buf, argv[0]);
  strcat (buf, "XXXXXX");

  fd = mkstemp(buf);
  if (fd >= 0)
    {
      struct file *new = (struct file *) malloc (sizeof *new);
      new->name = strdup (buf);
      new->next = files;
      files = new;
      /* Don't leak the file descriptor.  */
      close (fd);
      return buf;
    }

  /* Failure.  */
  fprintf (stderr, "mkstemp(%s) failed: %s\n", buf, strerror (errno));
  gmk_free (buf);
  return NULL;
}

int
mk_temp_gmk_setup (const gmk_floc *floc)
{
  printf ("mk_temp plugin loaded from %s:%lu\n", floc->filenm, floc->lineno);
  /* Register the function with make name "mk-temp".  */
  gmk_add_function ("mk-temp", gen_tmpfile, 1, 1, 1);
  return 1;
}

void
mk_temp_gmk_close ()
{
  while (files)
    {
      struct file *f = files;
      printf ("unlinking %s\n", f->name);
      unlink (f->name);
      free (f->name);
      files = f->next;
      free (f);
    }
  files = NULL;
  printf ("mk_temp plugin unloaded\n");
}


Now when you run make you’ll see something like:


$ make
mk_temp plugin loaded from makefile:1
Temporary file tmpfile.O7vuwn
unlinking tmpfile.O7vuwn
mk_temp plugin unloaded
cc -shared -fPIC -o mk_temp.so mk_temp.c
mk_temp plugin loaded from makefile:1
Temporary file tmpfile.lpgecm
Temporary file tmpfile.sIdBvo
unlinking tmpfile.sIdBvo
unlinking tmpfile.lpgecm
mk_temp plugin unloaded


Dmitry Goncharov <dgoncharov>
Sun 16 Oct 2022 12:43:02 AM UTC, comment #1: 

Make allows a loadable plugin to implement a setup function.
This patch adds the ability for a loadable plugin to optionally specify a close function.

Make calls this close function before unloading the plugin. This close function can be used for cleanup purposes.

The impl in this patch calls the close function of each loaded plugin before unloading and at exit, whether successful or not.
This impl does not call the close function when make is killed by a signal. It is possible to call the close function even when make is killed.
However
1. This would introduce restrictions on call that the close function can do.
2. Make is going to be modified to have the signal handler set a flag and handle the flag outside the signal handler.

Dmitry Goncharov <dgoncharov>
Sun 16 Oct 2022 12:17:42 AM UTC, original submission:  

.

Dmitry Goncharov <dgoncharov>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #53862:  sv63219.diff added by dgoncharov (7KiB - text/x-patch)
file #53863:  sv63219_test.diff added by dgoncharov (4KiB - text/x-patch)
file #53864:  sv63219_doc.diff added by dgoncharov (4KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by eliz (Posted a comment)
  • -email is unavailable- added by dgoncharov (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-05-14 psmith StatusNone Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone SCM
        Triage StatusNone Medium Effort
    2022-10-16 dgoncharov Attached File- Added sv63219.diff, #53862
        Attached File- Added sv63219_test.diff, #53863
        Attached File- Added sv63219_doc.diff, #53864

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code