public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* sys/stropts.h
@ 2020-03-04 14:26 stratus
  2020-03-04 17:24 ` sys/stropts.h Adhemerval Zanella
  0 siblings, 1 reply; 4+ messages in thread
From: stratus @ 2020-03-04 14:26 UTC (permalink / raw)
  To: libc-help

Dear GLIBC,
I just noticed sys/stropts.h has been removed. I was using a function closely derived from the GLIBC manual example, line 640 here which will need updating:
https://github.com/zqqw/consolelogga/blob/master/src/consolelogga.c

The new manual example seems to indicate the affected part can be deleted, and it seems to be only an error check that is probably not essential.
Is that correct, can I safely delete this part? I think it should be fine I guess.
  if (isastream (slave))
    {
      if (ioctl (slave, I_PUSH, "ptem") < 0
          || ioctl (slave, I_PUSH, "ldterm") < 0)
        goto close_slave;
    }

But also, when I was looking at the new example in the manual, I noticed there was a small oversight - the close_slave: goto tag is now unused.

https://www.gnu.org/software/libc/manual/html_node/Allocation.html#index-getpt
int
open_pty_pair (int *amaster, int *aslave)
{
  int master, slave;
  char *name;

  master = getpt ();
  if (master < 0)
    return 0;

  if (grantpt (master) < 0 || unlockpt (master) < 0)
    goto close_master;
  name = ptsname (master);
  if (name == NULL)
    goto close_master;

  slave = open (name, O_RDWR);
  if (slave == -1)
    goto close_master;

  *amaster = master;
  *aslave = slave;
  return 1;

close_slave:
  close (slave);

close_master:
  close (master);
  return 0;
}


Old version:
int
open_pty_pair (int *amaster, int *aslave)
{
  int master, slave;
  char *name;

  master = getpt ();
  if (master < 0)
    return 0;

  if (grantpt (master) < 0 || unlockpt (master) < 0)
    goto close_master;
  name = ptsname (master);
  if (name == NULL)
    goto close_master;

  slave = open (name, O_RDWR);
  if (slave == -1)
    goto close_master;

  if (isastream (slave))
    {
      if (ioctl (slave, I_PUSH, "ptem") < 0
          || ioctl (slave, I_PUSH, "ldterm") < 0)
        goto close_slave;
    }

  *amaster = master;
  *aslave = slave;
  return 1;

close_slave:
  close (slave);

close_master:
  close (master);
  return 0;
}

Yours sincerely,
zqqw.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sys/stropts.h
  2020-03-04 14:26 sys/stropts.h stratus
@ 2020-03-04 17:24 ` Adhemerval Zanella
  2020-03-04 17:55   ` sys/stropts.h Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Adhemerval Zanella @ 2020-03-04 17:24 UTC (permalink / raw)
  To: libc-help



On 04/03/2020 11:26, stratus@tuta.io wrote:
> Dear GLIBC,
> I just noticed sys/stropts.h has been removed. I was using a function closely derived from the GLIBC manual example, line 640 here which will need updating:
> https://github.com/zqqw/consolelogga/blob/master/src/consolelogga.c
> 
> The new manual example seems to indicate the affected part can be deleted, and it seems to be only an error check that is probably not essential.
> Is that correct, can I safely delete this part? I think it should be fine I guess.
>   if (isastream (slave))
>     {
>       if (ioctl (slave, I_PUSH, "ptem") < 0
>           || ioctl (slave, I_PUSH, "ldterm") < 0)
>         goto close_slave;
>     }

The commit [1] that has deleted the obsolete and never-implemented
XSI STREAM support also updated terminal documentation by removing
the very snippet your are referring. It should be safe on Linux
platforms, however I am not sure about platforms that actually have
POSIX conformant implementations (afaik Solaris for instance).

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=a0a0dc83173ce11ff45105fd32e5d14356cdfb9c

> 
> But also, when I was looking at the new example in the manual, I noticed there was a small oversight - the close_slave: goto tag is now unused.
> 
> https://www.gnu.org/software/libc/manual/html_node/Allocation.html#index-getpt
> int
> open_pty_pair (int *amaster, int *aslave)
> {
>   int master, slave;
>   char *name;
> 
>   master = getpt ();
>   if (master < 0)
>     return 0;
> 
>   if (grantpt (master) < 0 || unlockpt (master) < 0)
>     goto close_master;
>   name = ptsname (master);
>   if (name == NULL)
>     goto close_master;
> 
>   slave = open (name, O_RDWR);
>   if (slave == -1)
>     goto close_master;
> 
>   *amaster = master;
>   *aslave = slave;
>   return 1;
> 
> close_slave:
>   close (slave);
> 
> close_master:
>   close (master);
>   return 0;
> }
> 
> 
> Old version:
> int
> open_pty_pair (int *amaster, int *aslave)
> {
>   int master, slave;
>   char *name;
> 
>   master = getpt ();
>   if (master < 0)
>     return 0;
> 
>   if (grantpt (master) < 0 || unlockpt (master) < 0)
>     goto close_master;
>   name = ptsname (master);
>   if (name == NULL)
>     goto close_master;
> 
>   slave = open (name, O_RDWR);
>   if (slave == -1)
>     goto close_master;
> 
>   if (isastream (slave))
>     {
>       if (ioctl (slave, I_PUSH, "ptem") < 0
>           || ioctl (slave, I_PUSH, "ldterm") < 0)
>         goto close_slave;
>     }
> 
>   *amaster = master;
>   *aslave = slave;
>   return 1;
> 
> close_slave:
>   close (slave);
> 
> close_master:
>   close (master);
>   return 0;
> }

Yes, this needs to be fixed, thanks.

> 
> Yours sincerely,
> zqqw.
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sys/stropts.h
  2020-03-04 17:24 ` sys/stropts.h Adhemerval Zanella
@ 2020-03-04 17:55   ` Florian Weimer
  2020-03-04 18:09     ` sys/stropts.h Adhemerval Zanella
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2020-03-04 17:55 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-help

* Adhemerval Zanella:

> Yes, this needs to be fixed, thanks.

Are you going to fix this, or should I?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sys/stropts.h
  2020-03-04 17:55   ` sys/stropts.h Florian Weimer
@ 2020-03-04 18:09     ` Adhemerval Zanella
  0 siblings, 0 replies; 4+ messages in thread
From: Adhemerval Zanella @ 2020-03-04 18:09 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-help



On 04/03/2020 14:54, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> Yes, this needs to be fixed, thanks.
> 
> Are you going to fix this, or should I?

I will send a patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-04 18:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-04 14:26 sys/stropts.h stratus
2020-03-04 17:24 ` sys/stropts.h Adhemerval Zanella
2020-03-04 17:55   ` sys/stropts.h Florian Weimer
2020-03-04 18:09     ` sys/stropts.h Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).