Hi Dmitry,

Thanks for getting back to me.  Unfortunately I remember little of what
I learned while digging into this two years ago, so I don't know how to
recognise a properly configured pseudo-terminal master device or a
mis-configured operating system with a broken ptsname: I'm just running
Debian 10.3 with Gnome/Wayland.

All I was after was a program that could wrap gnome-terminal's shell
invocations, and add them to utmp, so:

  utmp_wrap /bin/bash -l

would use libutempter to create a utmp entry for each terminal window.
I attach example source that fails with libutempter as released, but
succeeds if it's patched as suggested above.

Are you saying that what I'm after is impossible because of security
concerns, or can you please suggest a means to make it work?

Best regards,
Conrad
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <utempter.h>
#include <wait.h>

int
main(int argc, char **argv)
{
  pid_t child;

  if(utempter_add_record(STDIN_FILENO, (char *) NULL) == 0) {
    perror("Couldn't add record to utmp");
    return EXIT_FAILURE;
  }

  if((child = fork()) == 0) {
    execv(argv[1], argv + 2);
    /*NOTREACHED*/
  }

  if(child < 0) {
    perror("fork failed");
    return EXIT_FAILURE;
  }

  if(waitpid(child, (int *) NULL, 0) != child) {
    perror("waitpid failed");
    return EXIT_FAILURE;
  }

  if(utempter_remove_record(STDIN_FILENO) == 0) {
    perror("Couldn't remove record from utmp");
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

Reply via email to