RE: [PATCH v1] KVM: selftests: name the threads

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Saturday, October 22, 2022 6:34 AM, Vipin Sharma wrote:
> On Mon, Oct 17, 2022 at 9:25 AM Wei Wang <wei.w.wang@xxxxxxxxx> wrote:
> > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c
> > b/tools/testing/selftests/kvm/lib/kvm_util.c
> > index f1cb1627161f..c252c912f1ba 100644
> > --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> > @@ -2021,3 +2021,50 @@ void __vm_get_stat(struct kvm_vm *vm, const
> char *stat_name, uint64_t *data,
> >                 break;
> >         }
> >  }
> > +
> > +/*
> > + * Create a named thread
> > + *
> > + * Input Args:
> > + *   attr - the attributes for the new thread
> > + *   start_routine - the routine to run in the thread context
> > + *   arg - the argument passed to start_routine
> > + *   name - the name of the thread
> > + *
> > + * Output Args:
> > + *   thread - the thread to be created
> > + *
> > + * Create a thread with user specified name.
> > + */
> > +void pthread_create_with_name(pthread_t *thread, const pthread_attr_t
> *attr,
> > +                       void *(*start_routine)(void *), void *arg,
> > +char *name) {
> > +       int r;
> > +
> > +       r = pthread_create(thread, attr, start_routine, arg);
> > +       TEST_ASSERT(!r, "thread(%s) creation failed, r = %d", name, r);
> > +       pthread_setname_np(*thread, name);
> 
> Since pthread_setname_np() expects "name" to be 16 chars including \0,
> maybe a strnlen(name, 16) check before it will be useful.

Yes. Alternatively, we should just check the return value of pthread_setname_np
and assert on any errors.




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux